[OS X TeX] Startup Items and Shutdown Items folders for TeXShop

Ramón Figueroa-Centeno ramonf at hawaii.edu
Sat Apr 18 20:38:06 EDT 2009


Aloha,

The last script I posted had a weird bug pertaining files with long names. Here is a fix:

-- Open the last "howmany" documents opened by TeXShop (if they exist) 

property howmany : 1

property prefName : "TeXShop.plist"


-- Get the front document of TeXShop 
try
	tell application "TeXShop" to get the front document
on error
	-- If there is no front document open the last one saved prior to quitting 
	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 i to 1
	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 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 f to alias (path of file f)
					exit repeat
				else
					set f to text 2 thru -1 of f
					if exists file f then
						set found to true
						set f to alias (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
				tell application "TeXShop" to open f
			end try
		end if
		
		set i to i + 1
		if i > howmany then
			exit repeat
		end if
	end repeat
end try

Sorry for the inconvenience. 

Enjoy!

Ramón
-- 
View this message in context: http://n2.nabble.com/Startup-Items-and-Shutdown-Items-folders-for-TeXShop-tp2618926p2657678.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.




More information about the MacOSX-TeX mailing list