Re: Recent Items
Re: Recent Items
- Subject: Re: Recent Items
- From: Thomas Fischer <email@hidden>
- Date: Sat, 12 Apr 2014 17:26:51 +0200
Hello,
just for the record I want to state that this can be done with acceptable speed with vanilla AppleScript (so that my last script doesn't stand as such). The first time might be a little slow to get System Events started, afterwards it's quick (in the order of 0.1 sec.).
This doesn't solve the problem of getting the current version of the recent application, and I don't know if there is way to force the Finder to update it.
set theChars to {}
set recentPrefs to (path to preferences folder from user domain as text) & "com.apple.recentitems.plist"
# set totalTime to start timer
tell application "System Events"
set recentApps to {}
value of property list file recentPrefs
RecentApplications of result
set theCustomItems to CustomListItems of result
set recentApps to {}
set appsNames to {}
set i to 1
repeat with anItem in every item of theCustomItems
copy (i & ": " & (|name| of anItem) as string) to the end of appsNames
set myBookmark to the Bookmark of anItem
try
set myBookmark to myBookmark as text
on error myBookmark
tell me to set anfang to (offset of "«data " in myBookmark) + 6
tell me to set ende to (offset of "»" in myBookmark) - 1
set myBookmark to text anfang thru ende of myBookmark
end try
set thePath to my decipherAbookmark(myBookmark)
copy thePath to the end of recentApps
set i to i + 1
end repeat
end tell
# set theEnd to stop timer totalTime
set maybe to (choose from list appsNames) # recentApps
if maybe is false then error number -128
set myChoice to item (word 1 of item 1 of maybe) of recentApps
ignoring application responses
tell application myChoice
activate
activate
end tell
end ignoring
# theEnd & myChoice
on decipherAbookmark(n)
set my theChars to {} & the id of (text 59 thru -1 of n)
set myCount to 0
set charList to ""
set theResult to 0
set tooLow to false
repeat with theid in my theChars
if theid > 96 then
set theNum to theid - 87
else if theid > 64 then
set theNum to theid - 55
else
set theNum to theid - 48
end if
if theNum ≥ 0 and theNum ≤ 16 then set theResult to 16 * theResult + theNum
set myCount to myCount + 1
if (myCount = 2) then
if theResult > 31 then
set charList to charList & character id theResult
set tooLow to false
else
if not tooLow then
set charList to charList & "/"
set tooLow to true
end if
end if
if charList ends with ".app" then return charList
set theResult to 0
set myCount to 0
end if
end repeat
end decipherAbookmark
Best
Thomas
Am 10.04.2014 um 18:11 schrieb koenig.yvan:
>
> Le 10/04/2014 à 14:39, Shane Stanley <email@hidden> a écrit :
>
>> On 10 Apr 2014, at 8:14 am, koenig.yvan <email@hidden> wrote:
>>
>>> Maybe somebody will have posted a fine code before I wake up.
>>
>>
>> Alas, you're probably wide awake by now. Here's an ASObjC-based handler to get just the names:
>>
>> use framework "Foundation"
>>
>> on returnRecentAppNames()
>> set thePath to current application's NSString's stringWithString:"~/Library/Preferences/com.apple.recentitems.plist"
>> set theDict to current application's NSDictionary's dictionaryWithContentsOfFile:(thePath's stringByExpandingTildeInPath())
>> return (theDict's valueForKeyPath:"RecentApplications.CustomListItems.Name") as list
>> end returnRecentAppNames
>>
>> And if you want the paths:
>>
>> use framework "Foundation"
>>
>> on returnRecentAppPaths()
>> set thePath to current application's NSString's stringWithString:"~/Library/Preferences/com.apple.recentitems.plist"
>> set theDict to current application's NSDictionary's dictionaryWithContentsOfFile:(thePath's stringByExpandingTildeInPath())
>> set theBookmarkData to (theDict's valueForKeyPath:"RecentApplications.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 end of thePaths to (theInfo's valueForKey:(current application's NSURLPathKey)) as text
>> end repeat
>> return thePaths
>> end returnRecentAppPaths
>>
>> --
>> Shane Stanley <email@hidden>
>> <www.macosxautomation.com/applescript/apps/>
>
>
>
> I can't post before because I was busy in the garden.
>
> As always your answer it's perfect.
>
> use theLib : script "RecentItems Lib"
>
> theLib's returnRecentAppPaths()
> (*
> {"/Applications/TextEdit.app",
> "/Applications/Applications_MAS/ClamXav.app",
> "/Applications/Applications perso/ouverture au démarrage/keep_clean_prefs.app",
> "/Applications/Safari.app",
> "/Applications/Applications perso/HexEdit Release/HexEdit.app",
> "/Applications/Mail.app",
> "/Applications/Utilities/AppleScript Editor.app",
> "/Applications/System Preferences.app",
> "/Applications/Preview.app",
> "/Volumes/Adobe Flash Player Installer/Install Adobe Flash Player.app"}
>
> Now, I must try to find where is stored the up-to-date list of recent items.
> The one stored in "~/Library/Preferences/com.apple.recentitems.plist" is out of date.
> In fact I don't know how often it's refreshed.
>
> The up-to-date list of names is :
>
> set theList to my nameOfSubMenuItems("Finder", 1, 9)
> set trueList to {}
> repeat with aString in theList
> set aString to contents of aString
> if aString is missing value then exit repeat
> if (aString is not "Applications") and aString ends with ".app" then
> set end of trueList to aString
> end if
> end repeat
> trueList
> --> {"Calculette.app", "ClamXav.app", "HexEdit.app", "keep_clean_prefs.app", "Moniteur d’activité.app", "Pages.app", "Pages.app", "Récupère le chemin.app", "Safari.app", "TextEdit.app"}
>
> #=====
>
> on nameOfSubMenuItems(theApp, mt, mi)
> activate application theApp
> tell application "System Events" to tell (first process whose frontmost is true) to tell menu bar 1 to ¬
> tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to return name of menu items
> end nameOfSubMenuItems
>
> #=====
>
>
> I tried to force Finder to quit but it didn't updated the file.
>
> Time to start a new safari.
>
> Yvan KOENIG (VALLAURIS, France) jeudi 10 avril 2014 18:11:46
>
>
>
> _______________________________________________
> 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
_______________________________________________
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