--AppleScript This script can be used in conjunction with TeXShop to clean up EOM source files. It replaces " and type chmod u+x eom_replace_for_mac.pl then press and type chmod u+x eom_refs.pl then press Now you can quit the Terminal app. -- enter location of perl scripts here set perlpath to "~/Documents/EOM_Scripts" -- ACTUAL SCRIPT STARTS BELOW - -- copy TeXShop front document into script_source tell application "TeXShop" set script_source to text of front document as «class utf8» end tell -- make a temporary file on which the perl scripts can operate set tempfile to make_temp_file() -- copy script_source into the temporary file write_to_temp_file(POSIX file tempfile, script_source) -- replace img strings by $•$ (inline maths) and table strings by $$•$$ (display maths) set tempstuff to (do shell script "cd " & perlpath & "; ./eom_replace_for_mac.pl " & " < " & quoted form of tempfile) -- replace content of tempfile with tempstuff write_to_temp_file(POSIX file tempfile, tempstuff) -- apply perl script (clean up references) to temporary file with output into a variable called tempstuff set tempstuff to (do shell script "cd " & perlpath & "; ./eom_refs.pl " & " < " & quoted form of tempfile) -- replace content of tempfile with tempstuff and convert to UNIX (LF) format; uses flip write_to_temp_file(POSIX file tempfile, tempstuff) do shell script "/bin/tcsh -c '~/Library/TeXShop/bin/flip -u " & tempfile & "'" -- copy everything back to the front document of TeXShop tell application "TeXShop" set text of front document to tempstuff as «class utf8» end tell -- move the cursor to the first "slot" $•$ or $$•$$ tell application "TeXShop" activate end tell tell application "System Events" tell process "TeXShop" key code 126 using command down key code 3 using {command down, control down} end tell end tell -- stuff below used to create temporary files and write to them on make_temp_file() set folder_name to path to temporary items set file_name to "eom_temp" & (random number from 100000 to 999999) set existing_file_names to list folder folder_name repeat while file_name is in existing_file_names set file_name to "eom_temp" & (random number from 100000 to 999999) end repeat return (POSIX path of folder_name) & file_name end make_temp_file on write_to_temp_file(temp_file, temp_text) set file_ref to open for access temp_file with write permission set eof file_ref to 0 write temp_text to file_ref as «class utf8» close access file_ref end write_to_temp_file