Hi All:
I’m trying to build a script that executes a set of commands on a file supplied by the user (via choose file). In order to do so properly, I need to test for the kind of file chosen. There are three options:
a) An Alias File
b) A .tex file
c) Anything else
How do I test for these three options? Suppose I’ve said
set chosenFile to (choose file)
I assume I’ll do something like:
If chosenFile [is an alias file] then
do something
If chosenFile [is a tex file] then
do something else
else cough up a hairball
end if
I’d appreciate any suggestions on what fills in the square brackets.
For what it’s worth, here’s the script that this is supposed to be a part of. I’ve indicated where the test for file type is supposed to come in.
set g to (choose file)
tell application "Finder" -- here comes the file test...
if g is an alias file then
set a to original item of g
if g is a .tex file then
set a to g
else
[exit the script with an error message]
set b to a's container as Unicode text --This gets the folder of the chosen file
set c to a's name --The name of the file
set d to a's name extension --The file extension of the file
end tell
set e to quoted form of POSIX path of b --This should deal with any spaces in the path, and give you a usable path for the terminal.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ("." & d)
set f to c's text item 1 --This will effectively remove the dot and the file extension from the file name
set AppleScript's text item delimiters to astid
{b, c, d, e, f}
tell application "Terminal"
do script "cd " & e & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; bibtex " & f & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; pdflatex -interaction=nonstopmode " & c & ¬
"; pdflatex -interaction=nonstopmode " & c
end tell
Thanks a lot,
Bernhard.