Selecting items in a smart folder

Dear All:

I’m trying to select an item from a Smart Folder (i.e., a saved search) in the course of running an AppleScript. But if I try to select it from the smart folder, nothing happens. It’s as if the file isn’t there. Do you have any thoughts?

Here is the script that I’m trying to run. The problem really just concerns the first line, where I’m trying to get a file.

set g to (choose file)
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}

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

thanks a lot,
Bernhard.

Bernhard:

I stumbled across a similar issue earlier this year, this is the thread that discusses it briefly. In essence, there is some kind of bug when using the Spotlight from within an AppleScript. As you can see from the thread, I changed it to a droplet, and it continues to function perfectly. (I just used that same droplet an hour ago.)

Hope this helps you out.