• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with Mavericks/Yosemite library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with Mavericks/Yosemite library


  • Subject: Problem with Mavericks/Yosemite library
  • From: Yvan KOENIG <email@hidden>
  • Date: Sat, 06 Jun 2015 18:25:49 +0200

Hello

I tried to use a library posted some times ago by Shane Stanley.
It's supposed to return the list of recent pathnames.

I discovered that it returned obsolete pathnames, those of deleted or moved files.
I'm not really surprised because the System is not guaranteed to keep the list up to date.

At first, I added some instructions in good old AppleScript language to drop the obsolete pathnames and it worked.

As I was not satisfied by the scheme, I decided to embed the library handler in the script as we may do in Yosemite.

Alas, I faced a wall which Shane demolished quickly. The keyword NSURL was conflicting with XMLLib.osax 's own nsurl.

As I am pig headed, I removed the annoying Osax and was able to continue to test.

At last, I was able to build a filter dropping the obsolete path without relying upon System Events (or the Finder).

Here is the code:


# Original instructions triggering a library
use scripting additions
use theLib : script "RecentItemsPaths Lib"
set theRecents to theLib's returnRecentDocsPaths()
set recentsAvailable to {}
tell application "System Events"
repeat with aRecent in theRecents
if exists disk item aRecent then set end of recentsAvailable to aRecent
end repeat
end tell
# New instruction using the embedded handler

set the_Recents to its returnRecentDocsPaths()

log theRecents # contain some obsolete pathnames
log recentsAvailable # contain only the valid pathnames
log the_Recents # contain only the valid pathnames

# Of course I don't understand why theRecents and the_Recents are different.

#=====
# The edited Library contain exactly what's below :

use framework "Foundation"
on returnRecentDocsPaths()
# CAUTION : when it's embedded in standard script this code conflicts against XMLLib.osax 
set defs to current application's NSUserDefaults's standardUserDefaults()
defs's addSuiteNamed:"com.apple.recentitems"
set theBookmarkData to (defs's valueForKeyPath:"RecentDocuments.CustomListItems.Bookmark") as list
set thePaths to {}
repeat with aData in theBookmarkData
set theInfo to (current application's NSURL's resourceValuesForKeys:{current application's NSURLPathKey} fromBookmarkData:aData)
set thePath to (theInfo's valueForKey:(current application's NSURLPathKey))
# Code filtering the obsolete pathnames
set anNSURL to (current application's NSURL's fileURLWithPath:thePath)
set valuesList to {current application's NSURLFileSizeKey}
set {attsNSDictionary, theError} to (anNSURL's resourceValuesForKeys:valuesList |error|:(reference))
if attsNSDictionary is not missing value then
set end of thePaths to thePath as text # Keep only the living pathnames
end if
end repeat
return thePaths
end returnRecentDocsPaths

I'm now facing a new wall.
I put the new code in the library file assuming that it will behave as it does in the script.
I was hoping to be able to re-install XMLLib.osax.

Alas, when it's in the library file, the handler behaves exactly as the original one: it doesn't filter the obsolete pathnames and I really don't understand why.
For sure I made something wrong but I can't guess what.

Yvan KOENIG (VALLAURIS, France) samedi 6 juin 2015 18:25:43







 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem with Mavericks/Yosemite library
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Button click in login screen pop-up window
  • Next by Date: numbers in words
  • Previous by thread: Re: Button click in login screen pop-up window
  • Next by thread: Re: Problem with Mavericks/Yosemite library
  • Index(es):
    • Date
    • Thread