Tell the current app/ID yrself so I can call you later -how?

In this shop on any single computer there are likely to be more than one copy of FileMaker Pro: FileMaker Pro 4, FileMaker Pro 6 (Classic), FileMaker Pro 6 (for OS X), FileMaker Unlimited, FileMaker Developer, etc etc etc. Furthermore, the copy currently running and existing as client of my database may or may not be renamed to “FileMaker Pro 6” or whatever. For these reasons, “tell the application ‘FileMaker Pro’” is a tricky business I generally avoid through the sneaky tactic of “tell the current application” insofar as FmPro itself executes the AppleScript as part of a FileMaker script and is therefore “current application”.

But now I’m in a routine where I have FileMaker telling other apps to do things, so that at the point I need to have AppleScript pass a value BACK to a FmPro field FileMaker is no longer the “current application”.

And if I end the AppleScript in mid-FileMaker-script and do something to bring FmPro to the front, the AppleScript variable that I’ve defined and set to a parameter earlier does not persist — e.g.,


tell the application "Terminal"
activate
do stuff
if the contents of window 1 contains "thestring"
set TheVariable to "yeah"
end if
end tell

followed by, in Filemaker
Refresh Window [bring to front]
Perform AppleScript →


tell the current application
set cell "CellName" to TheVariable as string
end tell

…doesn’t work because TheVariable doesn’t persist.

So what I want to do is something akin to this (except, of course, that it should WORK, which the following does not):


tell the current application
set MyFmPro to the process of the current application
end tell
tell the application "Terminal"
activate
do stuff
if the contents of window 1 contains "thestring"
set TheVariable to "yeah"
end if
do other stuff
end tell
if TheVariable="yeah"
tell the application MyFmPro
set cell "CellName" to "yeah"
end tell

(I need versions of this to run under both 9 and X, btw)

For a start, why are you bringing another application (e.g. Terminal.app) to the front at all? You can run a shell command and capture the contents of a terminal window regardless of whether terminal.app is frontmost or not.

Furthermore, why bother using terminal.app at all? You can use ‘do shell script’ in AppleScript (e.g. not targetting any application) and the shell command will be run, with the output of the shell command being passed back to the script:

set cmdOutput to do shell script "blah"
if cmdOutput contains "thestring"
 ... do your thang
end if

You might want to explore the use of the clipboard or writing/reading to a text file.