I have a similar question:
Why can’t I seem to use a variable to store the name of an application, then use the variable at the end of “using terms from application” line? Here’s my example, from a full project where a key pair is set in the user defaults file, the key pair is read and set as a variable, then the variable is used:
– in the startup script…
on will finish launching theObject
make new default entry at end of default entries of user defaults with properties ¬
{name:"primaryApp", contents:"<some program you want to talk to>"}
set targetApp to contents of default entry "primaryApp" of user defaults
log targetApp -- just to make sure it happened, and the variable dies at the end of this script anyway.
end will finish launching
The log points always check out correct.
– then, in the script that’s run by a button…
on clicked theObject
set targetApp to contents of default entry "primaryApp" of user defaults
-- set targetApp to (targetApp as string) Do I need something like this? I don't think I do...
log targetApp -- just to make sure it was read and set right...
using terms from application targetApp
tell application targetApp of machine targetMac
Event "<some event that targetApp recognizes>"
end tell
end using terms from
end clicked
The log points always check out correct here too.
Here’s the problem - the script won’t even compile! The error comes at the use of targetApp in the “using terms from” line, and the error is the dreaded and very not understood on my part “Syntax Error: Can’t make some data into the expected type.”
I’ve only this morning overcome the inability to use a variable to call out the remote machine, and also overcome my inability to use a variable for the application to talk to. Those problems were solved for me by using “using terms from” and NOW that’s not letting me use a variable either!
Can some kind sould explain to me if and how I need to somehow change the variable’s type, or use some sort of “delimiter” statement or something to get “using terms from” to use the darn thing?
Believe it or not there’s a reason why in this project I need to implement a preferences kind of thing where the user would set talking to a local copy of one or the other of two related applications, or one or the other of the same applications running on a remote machine where the two applications work with the same external events. It’s a very specific in-house application.
As always, thank you in advance.
Cheers,
WM