Re: tell syntax - specifying the APPL with a preset string
Re: tell syntax - specifying the APPL with a preset string
- Subject: Re: tell syntax - specifying the APPL with a preset string
- From: Christopher Nebel <email@hidden>
- Date: Tue, 6 Nov 2001 13:20:40 -0800
On Tuesday, November 6, 2001, at 08:09 AM, Doug McNutt wrote:
set theBrowser to "iCab"
. . . . .
on process(aURL, aFile)
tell application theBrowser
GetURL aURL to file aFile
end tell
end process
Results in a compile failure. Something about "expected end of line but
found identifier" but the Script Editor won't let me copy it for
pasting here. The item aURL is highlighted in the line that begins with
GetURL. I have tried adding theBrowser to the argument list but it
doesn't help. I haven't tried this:
"O appleScript processor, would you please make "theBrowser" a global
variable for me."
Using tell application "iCab" works OK. If I can't use a named variable
then why are the quotes required when the actual name is entered?
This gets into the whole "telling a variable" topic, which has been
extensively documented online.
The problem is that AppleScript needs to know at compile time exactly
what application you're talking about so it can get its custom
terminology, like, in this case, "GetURL". A constant string (e.g.
'tell application "iCab"') is fine, but when you use a variable (e.g.
'tell application theBrowser'), that's not defined at compile time.
AppleScript therefore tries to compile using only built-in terminology,
and "GetURL" isn't there, hence your error.
There are two ways around this. First, you can use raw codes, as JJ
suggested:
open location aURL given <<class dest>>:aFile
You only need one truly raw code, because the "open location" addition
has the same code as GetURL.
The other way is to use "using terms from", which was designed to solve
this exact problem -- you compute an application name at run time, but
you need to know at compile time what terms to use.
tell application theBrowser
using terms from application "iCab"
GetURL aURL to file aFile
end
end
Of course, "using terms from" is only defined in AppleScript 1.4 and
later. Some folks stick with the raw code approach for that reason.
--Chris Nebel
AppleScript Engineering