Re: why won't this compile?
Re: why won't this compile?
- Subject: Re: why won't this compile?
- From: Kai Edwards <email@hidden>
- Date: Sat, 29 Dec 2001 05:19:56 +0100
>
Date: Thu, 27 Dec 2001 22:32:22 -0700
>
Subject: why won't this compile?
>
From: "Donald S. Hall" <email@hidden>
>
To: AppleScript Mailing List <email@hidden>
>
>
This script compiles and runs fine (both OS 9.2.1, AS 1.6 & OS 10.1, AS 1.7)
>
>
--begin script 1 -------------------------------------
>
set theURL to "http://www.maccentral.com"
>
set theWindow to -1 -- top window
>
>
tell application "Internet Explorer"
>
OpenURL theURL toWindow theWindow Flags 7
>
end tell
>
--end script 1 ---------------------------------------
>
>
However, this script won't compile on either system:
>
>
--begin script 2 -------------------------------------
>
set theURL to "http://www.maccentral.com"
>
set theWindow to -1 -- top window
>
>
set browser to "Internet Explorer"
>
tell application browser
>
OpenURL theURL toWindow theWindow Flags 7
>
end tell
>
--end script 2 ---------------------------------------
>
>
Nor will this script:
>
>
--begin script 3 -------------------------------------
>
set theURL to "http://www.maccentral.com"
>
set theWindow to -1 -- top window
>
>
set browser to application "Internet Explorer"
>
tell browser
>
OpenURL theURL toWindow theWindow Flags 7
>
end tell
>
--end script 3 ---------------------------------------
>
>
In the latter two cases, "Check Syntax" produces an error message:
>
>
'Expected end of line, but found identifier.' The identifier highlighted is
>
theURL in the OpenURL statement.
>
>
What am I doing wrong, if anything?
While not wishing to get caught in the crossfire surrounding the 'using
terms from' vs. 'double-tell' debate, I hope I can (albeit belatedly) add
something of possible use to the advice you've already received.
It seems your aim is to send some instructions to an application (in this
case Internet Explorer) without specifically naming that application until
the script is run.
I recently had a similar experience when trying to compile a tell block
based on a variable, rather than an application name. Like you, I discovered
that the AppleScript compiler couldn't make sense of any
application-specific instructions within such a tell block.
As I understand it, when an application is named in the tell header, the
compiler accesses that application9s Apple Event dictionary and uses the
information to check the syntax within the tell block. However, with a
'tell-variable', this can't be done - simply because the script has to be
run before the variable is evaluated as an application.
The other consideration is whether you intend to run the script on different
machines - bearing in mind that the name of an application/version may not
be consistent in every case. To avoid the risk of a 'where is application X'
dialog, you could - as Steven Angier suggested - tell the Finder to use the
4-character creator type code (in this case "MSIE") to define the local
application's precise name.
To get the script to compile and run on a variety of systems, my personal
preference is to use raw syntax - to which Paul Berkowitz referred as an
option.
One hurdle here is laying your hands on the relevant raw events, constants,
classes, etc. (For my own purposes, I've compiled a FileMaker database that
converts the dictionary terms from my main applications to their raw
equivalents.)
Which brings me (at last!) to the main point of this note. If you want to
use raw syntax in your script, you could try something like this:
+ = option-\
; = shift-option-\
-- begin script -------------------------------------
tell application "Finder" to set appName to name of (application file id
"MSIE")
--> "Internet Explorer"
set browser to application appName
--> application "Internet Explorer"
set theURL to "
http://www.maccentral.com"
set theWindow to -1 -- top window
tell browser
+event WWW!OURL; theURL given +class WIND;:theWindow, +class FLGS;:7
--> OpenURL "
http://www.maccentral.com" toWindow -1 Flags 7
end tell
-- end script -------------------------------------
HTH (Well, it seems to work on the system I'm using tonight, anyway!)
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************