Three Issues: Smart Folder; "open with" an applescript; terminal

Hi All:

I have three queries. I hope putting them all in one post is acceptable.

  1. Choosing from a Smart Folder.
    I want to run a script on a file that the user chooses using “choose file”. Some of the files are in Smart Folders. When I run a script that tries to select a file via “choose file” and pick a file in a smart folder, the script simply ends. Nothing is selected. Do you know a solution to this issue?

  2. Suppose I want to run a script using the following set-up. In the finder, select a file. Then select the action “open with…”. I’d like to be in a position to select an applescript, where the file I’ve selected in the finder is the input. Any thoughts? (NB: I’m not trying to start the script first, and then select a file via “choose file”).

  3. One of the actions I’m running on an input is a command in the terminal application. I issue the “do script” command, and it works great. I would like to close the terminal application automatically once the command has been executed. One way not to do it is to issue the following command:


tell application "terminal"
do script "..."
quit
end tell

If I do it this way, the quit command is issued before the other command has run its course. So I need to test for whether the first command has been completed. For reference, I'm including the script I'm trying to run here.

The people on this BBS have been really great. Thanks a lot in advance.

Best,
Bernhard.


set g to (choose file)
(* Here is where my first two queries arise *)
tell application "Finder"
	set {file_Kind, file_Ext} to {g's kind, g's name extension}
	if file_Kind is "Alias" then
		set a to original item of g
	else
		if file_Kind is "LaTeX Source File" then
			set a to g
		else
			display dialog "Quitting script" giving up after 1
			error number -128 --[exit the script with an error message]    
		end if
	end if
	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
(* Here is where my third query arises *)
end tell

For the terminal portion have you tried using do shell script?

do shell 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