Definitive tell app as variable
Definitive tell app as variable
- Subject: Definitive tell app as variable
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 11 Mar 2001 23:49:22 -0800
I have long espoused Emmanuel Levy's version of the "tell app as variable"
because it was that little bit simpler than John Delacour's version, not
needing the <<class psn >> business. No one had ever found a flaw in it. But
I have just found it to fail, admittedly in special circumstances involving
a sort of bug in certain other applications. Nevertheless, under these
special circumstances, JD's version came through to save the day.
[Note: I'm using the << >> versions to represent option-\ and shift-option-\
for raw codes because of the character-mangling of AppleScript-Users'
server. This is also my first-ever double-posting to both lists, but this
has been such a long-standing discussion of importance, I hope no one
minds.]
The purpose of both methods is to be able to compile scripts to run on any
version of particular applications without the dreaded "Where is application
foo?" dialog box appearing on other users' machines. Emmanuel's version
involves setting the _name_ of an application to a variable like this:
set creaType to "MSNM" -- for example
tell application "Finder"
set appName to name of application file id creaType
if {appName} is not in (name of every process) then
open application file id creaType
end if
end tell
tell application appName
-- do stuff with raw codes
end tell
JD's version sets a variable to the application itself, after first setting
the Finder process as <<class psn >> to be able to use the 'tell [variable]'
construct:
set creaType to "MSNM" -- for example
tell application "Finder"
open application file id creaType
set appOE to first process whose creator type is creaType
set appOE to appOE as <<class psn >>
end tell
tell appOE
-- do stuff with raw codes
end tell
So far, they had both seemed to work equally well.
Just last week, I discovered that the problem which Outlook Express,
Microsoft Entourage and various other apps have with properties of the
application itself whereby you have to use 'get' or set them to a variable
before you can evaluate them manifests itself in another way when using raw
codes. For example, the raw code for 'default mail account' is <<class
dfAc>> .If you say
tell application "Outlook Express"
get <<class dfAc>>
end tell
the result is
--> default mail account of application "Outlook Express"
rather then the evaluation of it as 'POP account id 1', for example. The
solution turned out to be the roundabout
tell application "Outlook Express"
get <<class dfAc>> of application "Outlook Express"
end tell
--> POP account id 1 of application "Outlook Express"
This arose naturally when using raw codes using JD's version. And the
solution there worked:
set creaType to "MSNM"
tell application "Finder"
open application file id creaType
set appOE to first process whose creator type is creaType
set appOE to appOE as <<class psn >>
end tell
tell appOE
get <<class dfAc>> of appOE
end tell
--> POP account id 1 of application "Outlook Express"
(It doesn't work if you omit the final 'of appOE').
But, I've just discovered that it does NOT work with Emmanuel's version:
set creaType to "MSNM"
tell application "Finder"
set appName to name of application file id creaType
if {appName} is not in (name of every process) then
open application file id creaType
end if
end tell
tell application appName
get <<class dfAc>> of application appName
end tell
-->ERROR: Can't get default mail account of application "Outlook Express"
No amount of (contents of) or (get) helps here. JD's version wins.
I haven't used raw codes much. I just sent Walter Kaye a raw code version of
two scripts in raw code at his request, on MacScrpt. Then I tried to run
them and found this error. I'll send a correction to MacScrpt shortly.
--
Paul Berkowitz