• 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
Re: Recent Items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recent Items


  • Subject: Re: Recent Items
  • From: Thomas Fischer <email@hidden>
  • Date: Sun, 13 Apr 2014 14:17:30 +0200

Hello Yvan,

I chose to display the *localized names* of the applications, since showing the American names might be confusing. If I want to disambiguate the names of applications, I just rename them, like renaming Numbers v. 2.3. to "Numbers 2.3.app". Otherwise, one could put more "Intelligence" into the script to somehow disambiguate names if they occur more than once, or just fall back to the full path.

As you saw, if you only want the list of paths, you can change the choice section to
set maybe to (choose from list recentApps) # appsNames
if maybe is false then error number -128
# set myChoice to item (word 1 of item 1 of maybe) of recentApps
set myChoice to item 1 of maybe
This works on my machine as expected (German localization of Mac OS 10.6.8) – unless there are Umlauts in the name of the path, more on this below.

Am 12.04.2014 um 21:42 schrieb koenig.yvan:


Le 12/04/2014 à 17:26, Thomas Fischer <email@hidden> a écrit :

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.

…

It seems that you missed what was the goal to reach.

I ran your script and was asked to select an application in the list appsNames

appsNames was

{"1: Éditeur AppleScript.app", 
"2: Numbers.app", 
"3: iBooks.app", 
…
"18: trier uninstall.app", 
"19: Numbers.app", 
"20: TextEdit.app"}

Alas doing that I can't know which application Numbers.app is the 2.3 one and which is the 3.2 one.
It was the real goal to reach. Other apps are available only once. The problem is with iWork components because iWork '09 offer true applications when iPlay '13 offer just toys.
But I can't wait too long before learning what is already available in these toys.

As I am curious, I looked at the list named recentApps and got an awful result.


{"/0/Applications/Utilities/AppleScript Editor.app", 
"/Applications/iWork '09/Numbers.app", 
"/ä/Applications/iBooks.app", 
…
"/l/Users/••••••••••/Desktop/trier uninstall.app", 
"/ä/Applications/Numbers.app", 
"/ä/Applications/TextEdit.app"}

There is obviously something wrong.
My script is based on a very crude understanding of the format of Bookmarks, I didn' find much about it on the net
(e.g. http://superuser.com/questions/347248/use-a-script-to-grab-paths-to-the-recently-changes-files-on-the-system),
not enough to really make this work better.
It seems that sometimes between OS 10.6.8 and OS 10.9 the format changed, and the analysis has to start later, something like 
set my theChars to {} & the id of (text 119 thru -1 of n)
seems to do the job.


If I select item 19, the script try to start "/ä/Applications/Numbers.app", 
and of course I get the error :
error "Le fichier /ä/Applications/Numbers.app est introuvable." number -43 from current application
…
This said, I looked in depth in your code to see how you converted so quickly hexadecimal into decimal then character.
So I understood why you got extraneous characters at the beginning of the pathnames.
You aren't extracting the pathname stored as a single string near the end of the bookmark (highlighted in blue) but you rebuild it from its components (highlighted in purple) stored separately at the beginning.

Here is a raw bookmark.
…
Now is the same deciphered by my very first script. A lot of characters don't appear because their ID is lower than 32.

(*book`0? ApplicationsApplications persoouverture au deÌ?marragekeep_clean_prefs.app4Têùr?1⁄2tÚ??¨¸A23ÓÜ Macintosh HD??-èAµábÕ$BB557A65-EA72-38F3-BCD6-85AEBCB9B305?ï/ßa86a64f52149399ddff934cc2cdddbbc89acec83;00000000;00000000;0000000000000020;com.apple.app-sandbox.read-write;00000001;01000001;0000000000da74bd;/applications/applications perso/ouverture au deÌ?marrage/keep_clean_prefs.app?<thorn>ÿÿÿ pÈ<eth>@à ?  D $ 4  p0 ??<eth>?*)

The problem with your code is that it is fooled by what it scan at the beginning of the bookmark.

My understanding is that if you replace :

set my theChars to {} & the id of (text 59 thru -1 of n)
by
set my theChars to {} & the id of (text 123 thru -1 of n)

Yes, I couldn't quite figure out where to start. In any case it has to be odd!

you will get paths starting with their true starting point.
Of course this is not sufficient to solve the problem due to unicode characters stored as more than one byte. I underlined the groups of three bytes describing the character «é»

Yes, in addition to the crude bookmark converter one would need some UTF-8 converter.
Could you please try this version on your machine? This uses 123 as starting point and displays the paths of the applications.
This version seems to work on your bookmark example.

set theChars to {}
set newChars 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 recentApps) # appsNames
if maybe is false then error number -128
# set myChoice to item (word 1 of item 1 of maybe) of recentApps
set myChoice to item 1 of maybe
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 123 thru -1 of n)
set my newChars to {}
set myCount to 0
set theResult to 0
set tooLow to false
set firstSum to 0
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
if not tooLow then
copy 47 to the end of my newChars
set tooLow to true
end if
else
set tooLow to false
if theResult < 129 then
copy theResult to the end of my newChars
else if theResult < 192 then
copy firstSum * 64 + (theResult - 128) to the end of my newChars
set firstSum to 0
else if theResult < 224 then
set firstSum to firstSum * 64 + (theResult - 192)
else if theResult < 240 then
set firstSum to firstSum * 64 + (theResult - 224)
else if theResult < 245 then
set firstSum to firstSum * 64 + (theResult - 240)
end if
end if
if my newChars ends with {46, 97, 112, 112} then return character id (my newChars) #exit repeat
set theResult to 0
set myCount to 0
end if
end repeat
end decipherAbookmark

Best
Thomas



 _______________________________________________
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: Recent Items
      • From: Thomas Fischer <email@hidden>
References: 
 >Recent Items (From: "koenig.yvan" <email@hidden>)
 >Re: Recent Items (From: Shane Stanley <email@hidden>)
 >Re: Recent Items (From: "koenig.yvan" <email@hidden>)
 >Re: Recent Items (From: Thomas Fischer <email@hidden>)
 >Re: Recent Items (From: "koenig.yvan" <email@hidden>)

  • Prev by Date: Re: Recent Items
  • Next by Date: QuickTime Pro 7 Captions
  • Previous by thread: Re: Recent Items
  • Next by thread: Re: Recent Items
  • Index(es):
    • Date
    • Thread