[OS X TeX] A script to get the list of recently opened files of an application (e.g. TeXShop)
Ramón Figueroa-Centeno
ramonf at hawaii.edu
Sun Apr 19 02:28:44 CEST 2009
Aloha,
I found a bug with my previously posted script pertaining files with long names. Below is a fix.
-- Script that get the list of recently opened items from an application's preference plist
-- Note: The application probably must quit before this list gets updated.
property prefName : "TeXShop.plist"
set p2p to (path to preferences from user domain as text) & prefName
tell application "System Events"
try
set listRecents to value of property list item "NSRecentDocumentRecords" of property list file p2p
on error
return
end try
end tell
set Recent to {}
repeat with r in items of listRecents
set alis to |_NSAlias| of |_NSLocator| of r
try
alis as text
on error errmsg
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "****"
set errmsg to text item 2 of errmsg
set AppleScript's text item delimiters to "»"
set errmsg to text item 1 of errmsg
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to savedDelimiters
end try
set decode to do shell script "echo " & quoted form of errmsg & " | xxd -r -p"
set nullchar to ASCII character 0
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to nullchar
set maybe to {}
repeat with p in text items of decode
if ((count of p) > 1) and p contains ":" then copy p to end of maybe
end repeat
tell application "System Events"
set found to false
repeat with f in maybe
if exists file f then
set found to true
set fpath to path of f
exit repeat
else
set f to text 2 thru -1 of f
if exists file f then
set found to true
set fpath to path of file f
exit repeat
end if
end if
end repeat
end tell
set AppleScript's text item delimiters to savedDelimiters
if found then
try
copy fpath to end of Recent
end try
end if
end repeat
return Recent
Enjoy!
Ramón
--
View this message in context: http://n2.nabble.com/A-script-to-get-the-list-of-recently-opened-files-of-an-application-%28e.g.-TeXShop%29-tp2631029p2657654.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.
More information about the macostex-archives
mailing list