<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>ROOT</string>
	<key>submenu</key>
	<array>
		<dict>
			<key>content</key>
			<string>--Applescript direct

-- Save a font set to ~/Library/TeXShop/bin/SetFonts.tex
-- The companion script setfonts allows you to choose a font set from that file.
-- Font set commands are delimited by %SetFonts lines.
-- In none are found, the script fails.
-- If you add DELETE after the first %SetFonts (same line), SaveFontSet deletes the item.
-- The line following the first %SetFonts must be %&lt;title&gt;, where &lt;title&gt; is the ID for the set..
-- If you add DEFAULT after the first %SetFonts (same line), 
-- SaveFontSet makes it the default selection when using setfonts.
--Last revised 01/11/2011
-- Michael Sharpe, msharpe@ucsd.edu
global lf
set lf to (ASCII character 10)
set path_to_setfonts to (POSIX path of (((path to home folder) as string) &amp; "Library:TeXShop:bin:SetFonts.tex"))
set msg to 0
tell application "Finder" to if exists path_to_setfonts as POSIX file then set msg to 1
set thefile to POSIX file path_to_setfonts
if msg = 0 then
	set ref_num to open for access thefile with write permission
	set eof of ref_num to 0
	write lf &amp; "%SetFonts" &amp; lf to ref_num
	write "% Latin Modern" &amp; lf to ref_num
	write "% Extension of CM text+math" &amp; lf to ref_num
	write "\\usepackage{lmodern} % math, rm, ss, tt" &amp; lf to ref_num
	write "\\usepackage[T1]{fontenc}" &amp; lf to ref_num
	write "\\usepackage{textcomp}" &amp; lf to ref_num
	write "\\usepackage[bb=boondox,frak=boondox,cal=rsfso]{mathalfa}" &amp; lf to ref_num
	close access thefile
end if
open for access thefile
set file_contents to (read thefile)
close access (thefile)
set oldtid to AppleScript's text item delimiters
set AppleScript's text item delimiters to lf&amp;"%SetFonts"
set fontlist to the text items of file_contents
set namelist to {}
set fcnt to count (fontlist)
if fcnt &gt; 1 then
	repeat with i from 2 to fcnt
		try
			set s to trim(true, item i of fontlist)
			set end of namelist to trim(true, text 2 thru -1 of first paragraph of s)
		on error
			set end of namelist to "---"
		end try
		--set end of namelist to trim(true, text 2 thru -1 of first paragraph of item i of fontlist)
	end repeat
end if

--break the document into 3 pieces--part before 1st %SetFonts,between and after 2nd
tell application "TeXShop"
	set whole_document to (the text of the front document) as string
end tell
set AppleScript's text item delimiters to lf &amp; "\\begin{document}"
set prepost to text items of whole_document
set preamble to (item 1 of prepost)
set AppleScript's text item delimiters to lf &amp; "%SetFonts"
set doc_items to the text items of preamble
set AppleScript's text item delimiters to oldtid
set n to count of doc_items

if not (n = 3) then
	display dialog "Your preamble does not contains exactly two %SetFonts lines. Bailing out." buttons "OK" default button "OK"
	return
end if
set s to item 2 of doc_items
set L to stroffset(lf,s) - 1
set flag to 0 --1 for DELETE, 2 for DEFAULT
if L &gt; 5 then
	set t to trim(true, text 1 thru L of s)
	if t = "DELETE" then
		set flag to 1
	else
		if t = "DEFAULT" then
			set flag to 2
		end if
	end if
end if

set newfs to trim(true, text (L + 2) thru (count of s) of s)
if first character of newfs is not "%" then
	display dialog "Your %SetFonts block lacks a title beginning with %. Bailing out." buttons "OK" default button "OK"
	return
end if
set fs to trim(true, text 2 thru -1 of first paragraph of newfs)
if count of fs is 0 then
	display dialog "Your %SetFonts block lacks a non-empty title. Bailing out." buttons "OK" default button "OK"
	return
end if
set fsidx to getidx(fs, namelist) + 1
--check for existing DEFAULT
set dfltflag to false
try
	set AppleScript's text item delimiters to lf
	set defline to last paragraph of (trim(true, item 1 of fontlist))
	--display dialog "defline=" &amp; defline
	if (count of defline) &gt; 8 then
		if (text 1 thru 8 of defline) = "DEFAULT=" then
			set dfltflag to true
		end if
	end if
on error
	
end try
if flag = 2 then
	if dfltflag then --there is an existing DEFAULT
		set deflines to text items of trim(true, item 1 of fontlist)
		--display dialog "deflines(-1)=" &amp; item -1 of deflines
		set item -1 of deflines to "DEFAULT=" &amp; fs
		set (item 1 of fontlist) to deflines as string
	else
		set (item 1 of fontlist) to (item 1 of fontlist) &amp; lf &amp; "DEFAULT=" &amp; fs
	end if
end if
if fsidx = 1 then --not in current list
	if flag = 0 then
		set end of fontlist to lf &amp; trim(true, newfs)
	else
		if flag = 1 then --DELETE
			display dialog "Cannot delete--name not found. Bailing out." buttons "OK" default button "OK"
			return
		end if
	end if
else
	if flag = 0 then
		set item fsidx of fontlist to lf &amp; trim(true, newfs)
	else
		if flag = 1 then --DELETE
			if fsidx = (count of fontlist) then
				set fontlist to items 1 thru -2 of fontlist
			else
				set fontlist to items 1 thru (fsidx - 1) of fontlist &amp; items (fsidx + 1) thru -1 of fontlist
			end if
		end if
	end if
end if
set ref_num to open for access thefile with write permission
set eof of ref_num to 0
set AppleScript's text item delimiters to lf &amp; "%SetFonts"
write (fontlist as string) to ref_num
close access thefile
display dialog "Your %SetFonts block was saved to SetFonts.tex." buttons "OK" default button "OK"
--whole_document

on getidx(this_item, this_list)
	if this_item = "&lt;none&gt;" then
		return 0
	else
		set n to the count of this_list
		repeat with i from 1 to n
			if item i of this_list is this_item then return i
		end repeat
		return 0
	end if
end getidx

on sort(the_list)
	set old_delims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {ASCII character 10}
	set list_string to (the_list as string)
	set new_string to do shell script "echo " &amp; quoted form of list_string &amp; " | sort -f -u"
	set new_list to (paragraphs of new_string)
	set AppleScript's text item delimiters to old_delims
	return new_list
end sort

on trim(theseCharacters, someText)
	-- Lazy default (AppleScript doesn't support default values)
	if theseCharacters is true then set theseCharacters to ¬
		{" ", tab, ASCII character 10}
	
	repeat until first character of someText is not in theseCharacters
		set someText to text 2 thru -1 of someText
	end repeat
	
	repeat until last character of someText is not in theseCharacters
		set someText to text 1 thru -2 of someText
	end repeat
	
	return someText
end trim

on stroffset(find_str,whole_str) 
--replacement for offset, which fails in late 2011 TeXShop applescript direct
--note that length fails too, but may be replaced by count
	if (count of whole_str)=0 then return 0
	if (count of find_str)=0 then return 0
	set tid to Applescript's text item delimiters
	set Applescript's text item delimiters to {find_str}
	set lst to text items of whole_str
	set Applescript's text item delimiters to tid
	if (count of lst)=1 then
		return 0
	else
		return (count of (item 1 of lst)+1)
	end if
end stroffset</string>
			<key>name</key>
			<string>SaveFontSet</string>
		</dict>
	</array>
</dict>
</plist>
