tell statement with a variable problem

I found that a script would break when I replaced a tell statement with a constant application with a tell statement with a variable application, but not on the tell line, but on a farther line(examples below). I think this has to do with the use of the tell statement to load dictionaries, i.e. it can’t find the dictionary word if the tell statement uses a variable… Have other’s seen this? Shouldn’t this be set up with an improved error message, or mention in the Language Guide, or the FAQ, etc?


set qApp to a reference to application "Mail"
tell application "Mail"
outgoing message
end tell

Breaks: (on line “outgoing message”)

set qApp to a reference to application "Mail"
tell qApp
outgoing message
end tell[

When you switch to the variable, you’re right, AS doesn’t know how to interpret the specific terms from the variable application’s dictionary. The way around this is to wrap your variable application tell block in a “using terms from application…” block like so:


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Thanks; that makes sense. I didn’t know about the “use terms” command. It turned out I didn’t need to be doing this, but it’s all good.

I have similar problem. It doesn’t solve the problem that the application name can’t be a variable. What type of variable to be used after application?

Please tell me how to correct the following code.
Thanks a ton!

set app_name to "Mail"
tell application app_name
using terms from application app_name
[do something]
end using terms from
end tell

The using terms from block has to wrap the tell block of the variable app and has to be specific to an app resident on the developers machine:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks jon.

Do you mean that I can’t use a variable in the statement “using temr from”?

If it is so, it pretty limits the way to interactive with Applescript. :?

Yes, that is what I mean. You’re missing the point of using this construct. It is meant so that you can compile your script in a way that allows you to distribute it and test for the existence of the target app on the end user’s machine without knowing beforehand what they’ve named the app, where it’s installed, or even if it’s installed at all. What is it that you want to do? Why do you need to make the application variable?


What i waant is pretty simple. to write script that can be modified to run with different applications.

For example, I wanna write a script that replace a few elements in FreeHand. Each of those elements has a different tag for identifying. I call a function to do it in a loop with different values in a list. Due to the fact that FreeHand is not very scriptable, I have to call “System Events” to handles it in the fucntion and it requires the application name to be passed everytime in order to get the work done inside the loop. It would be nice to set the application reference or application name as a variable to writ those function in general.

Once again, thank for you help.

Then why are you using this construct? You know that you are either scripting FreeHand directly or targeting System Events, what’s variable there?