[OS X TeX] Open related... macro
Herbert Schulz
herbs at wideopenwest.com
Fri Feb 13 21:14:28 CET 2009
On Feb 13, 2009, at 1:24 PM, Josep Maria Font wrote:
> I have always wanted to have an "Open related..." macro in TeXShop
> that lets you select and open one of the "related" files associated
> with the current file: the results of some typesetting jobs may
> imply you need to read some of them to solve some problems, etc.
> Instead of issuing a "feature request" I decided to try to write it
> myself, by modifying the macro "Open quickly..." that comes bundled
> with TeXShop and customizing it "to your liking", as it says.
>
> What I did was just change the list of extensions that are searched
> for:
>
> property extensions_to_open : {"bbl", "toc", "log", "aux"}
>
> And now, it happens that it does not work. It only finds the .log
> and .aux files, no .toc or .bbl is found (and they are there!). If I
> leave only the first two, Applescript complains that it cannot find
> any files with those extensions.
>
> By the way, the error message gives a wrong description of the
> error, it says "Finder got an error: Can't get name of every file of
> folder [the folder's path, rightly found] whose {"bbl", "toc"}
> contains name extension"; it should say "... whose name extension
> contains {"bbl", "toc"}". But this is a minor point.
>
> The macro fails when clicking the "test" button, and also fails
> after having saved it, if either called from the macro menu or from
> the assigned key equivalent. It also fails after restarting TeXShop.
>
> I have customized other macros (many .bib templates, for instance)
> with success, but don't know Applescript own language. Any ideas ?
> Thanks.
>
>
> JMaF
Howdy,
Are you using OS X 10.5.x (Leopard)? Something with Applescript
changed in Leopard and the macro has to be rewritten to bypass the
problem. At some point Dick Koch figured out how to fix another macro,
written by Will Robertson, that I use quite often to clean up files.
Here's the version that works, hopefully you'll be able to adapt it to
fix the Open Quickly... macro:
-------------------------------------
--Applescript direct
-- CUSTOMISE TO YOUR LIKING:
property extensions_to_delete : {"acn", "acr", "alg", "aux", "bak",
"blg", "brf", "dep", "dvi", "ent", "fdb_latexmk", "glg", "gls", "fff",
"glo", "idv", "idx", "ilg", "ind", "ist", "lg", "loa", "lof", "log",
"lot", "mtc", "mlf", "nav", "out", "pdfsync", "ps", "snm", "synctex",
"toc", "tmp", "ttt", "tui", "tuo", "wrm", "xref", "4ct", "4tc"}
property delete_files_only_with_same_name : true
-- If your file is document.tex, setting this true will delete only
document.aux, document.log, etc., but NOT otherdoc.aux, otherdoc.log,
etc.
-- Otherwise, ALL files with the extensions_to_delete will be deleted.
-- Clean Up By Will Robertson 8/17/2004
-- Fixed For Leopard By Dick Koch 12/11/2007
-- THE SCRIPT:
tell application "TeXShop"
set texpath to alias POSIX file #TEXPATH# -- gives "/path/to/docu.tex"
tell application "Finder"
set texfolder to the container of (texpath as alias)
if delete_files_only_with_same_name then
set texname to the name of (texpath as alias)
set texname to do shell script "echo " & the quoted form of texname
& " | cut -f 1 -d '.' "
set texfiles to every file in texfolder whose name contains
(texname & ".")
else
set texfiles to every file in texfolder
end if
end tell
set files_to_delete to {}
set filenames_to_delete to {}
repeat with this_file in texfiles
set actualname to the name of this_file
set actualextension to do shell script "echo " & the quoted form of
actualname & " | cut -f 2 -d '.'"
-- if (the name extension of this_file is in extensions_to_delete)
then
if (actualextension is in extensions_to_delete) then
set the end of files_to_delete to (this_file)
set the end of filenames_to_delete to " " & (the name of
this_file as string) & return
end if
end repeat
display dialog "Are you sure you want to move the following files to
the trash?" & return & filenames_to_delete as string buttons {"Keep",
"Trash"} default button "Trash" with icon caution
if the button returned of the result is "Trash" then
tell application "Finder" to move every item of files_to_delete to
the trash
end if
end tell
-------------------------------------
Good Luck,
Herb Schulz
(herbs at wideopenwest dot com)
More information about the macostex-archives
mailing list