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

Ramón Figueroa-Centeno ramonf at hawaii.edu
Wed Apr 15 05:02:11 CEST 2009


Here is a variant to the previous script that only opens the last n opened documents if there is not one open already. The effect is that if you launch TeXShop by double clicking a document then only that document opens, if you launch TeXShop by double clicking it (or clicking in the Dock or some other launcher) then the last n documents will open. This behavior seems to me to be more sane :)

-- 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
					exit repeat
				else
					set f to text 2 thru -1 of f
					if exists file f then
						set found to true
						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


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




More information about the macostex-archives mailing list