• 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: Thu, 10 Apr 2014 14:07:07 +0200

Hello Yvan,

now I understand what you're after. But I don't really understand the format of the bookmark entry, thus this is a terrible hack.
And it still is pretty slow, so there should be a better way to do this.
Is there any unix command that lets you evaluate these bookmarks?

So, this is my AppleScript suggestion:

global tids
set recentPrefs to (path to preferences folder from user domain as text) & "com.apple.recentitems.plist"
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
set myString to "/" & character id {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
set tids to every character of myString

#set AppleScript's text item delimiters to tids

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 {}
	repeat with anItem in every item of theCustomItems
		set myBookmark to the Bookmark of anItem
		try
			set myBookmark to myBookmark as text
		on error myBookmark
			set anfang to (offset of "«data" in myBookmark) + 6
			set ende to (offset of "»" in myBookmark) - 1
			set myBookmark to text anfang thru ende of myBookmark
			log myBookmark
		end try
		set theName to my decipherAbookmark(myBookmark)
		copy theName to the end of recentApps
	end repeat
	set AppleScript's text item delimiters to oTIDs
end tell
set maybe to choose from list recentApps
if maybe is false then error number -128
ignoring application responses
	activate application (maybe as text)
end ignoring

on decipherAbookmark(theString)
	set bookMarkString to HexToString(theString)
	log "Transformed: " & bookMarkString
	set ende to offset of ".app" in bookMarkString
	set bookMarkString to text 30 thru (ende + 3) of bookMarkString # 30 is a crude guess!
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tids}
	set theFolders to every text item in bookMarkString
	set thePath to {}
	repeat with theFolder in theFolders
		if (the length of theFolder is not 0) then
			copy theFolder as text to the end of thePath
		end if
	end repeat
	set theName to "/" & thePath as text
	set AppleScript's text item delimiters to oTIDs
	return theName
end decipherAbookmark

on HexToString(n)
	set n to {} & the id of n
	set myCount to 0
	set charList to {}
	set theResult to 0
	repeat with theid in n
		if (myCount mod 2 = 0) then
			copy character id theResult to the end of charList
			set theResult to 0
		end if
		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
	end repeat
	return charList as text
end HexToString



Am 10.04.2014 um 00:14 schrieb koenig.yvan:

> Im asked for a script allowing to start a recently used application without triggering the Apple Menu.
>
> I wrote such a script but I'm not satisfied of it because the deciphering of the datas stored in the preference file storing the info upon these item is slow and mistreat the Unicode characters which we use in French.
>
> Here is a draft of the script.
>
> #[SCRIPT]
> set recentPrefs to (path to preferences folder from user domain as text) & "com.apple.recentitems.plist"
> 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 {}
> 	repeat with anItem in every item of theCustomItems
> 		set end of recentApps to my decipherAbookmark(bookmark of anItem)
> 	end repeat
> end tell
>
> set maybe to choose from list recentApps
> if maybe is false then error number -128
> activate application (maybe as text)
>
> #=====
> #
> # It's this handler which is boring me
> #
> on decipherAbookmark(bMark)
> 	try
> 		bMark as text
> 	on error errMsg number errNbr
> 		offset of "«data" in errMsg
> 		set errMsg to text (result + 6) thru -1 of errMsg
> 		offset of "»" in errMsg
> 		set errMsg to text 1 thru (result - 1) of errMsg
> 		set enListe to {}
> 		repeat with i from 1 to count errMsg by 2
> 			try
> 				tell me to set end of enListe to character id (my hex2num(text i thru (i + 1) of errMsg))
> 			end try
> 		end repeat
> 		set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
> 		set enTexte to enListe as text
> 		set enTexte to item -2 of my decoupe(enTexte, ".app")
> 		set enTexte to item -1 of my decoupe(enTexte, ";") & ".app"
> 		set AppleScript's text item delimiters to oTIDs
> 		return enTexte
> 	end try
> end decipherAbookmark
>
> #=====
>
> on decoupe(t, d)
> 	local oTIDs, l
> 	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
> 	set l to text items of t
> 	set AppleScript's text item delimiters to oTIDs
> 	return l
> end decoupe
>
> #=====
>
> on hex2num(t)
> 	return ((offset of (text item 1 of t) in "0123456789ABCDEF") - 1) * 16 + (offset of (text item 2 of t) in "0123456789ABCDEF") - 1
> end hex2num
>
> #=====
> #[/SCRIPT]
>
> I'm quite sure that there is a better way to convert the piece of Hex datas into text.
> Probably I have a Shane Stanley's library to do that but my memory tell me that somebody published a tip using a temporary file to do decipher the bookmark.
> It's passed midnight here so it's time to sleep.
>
> Maybe somebody will have posted a fine code before I wake up.
>
> Yvan KOENIG (VALLAURIS, France) jeudi 10 avril 2014 00:13:28
>
>
>
>
> _______________________________________________
> 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


References: 
 >Recent Items (From: "koenig.yvan" <email@hidden>)

  • Prev by Date: NSString in ApplescriptObjC
  • Next by Date: Re: NSString in ApplescriptObjC
  • Previous by thread: Re: Recent Items
  • Next by thread: Re: Recent Items
  • Index(es):
    • Date
    • Thread