Specifying OS X/9 versions of an app [LONG] [WAS: Re: why won't this compile?]
Specifying OS X/9 versions of an app [LONG] [WAS: Re: why won't this compile?]
- Subject: Specifying OS X/9 versions of an app [LONG] [WAS: Re: why won't this compile?]
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 29 Dec 2001 00:02:17 -0800
On 12/28/01 11:00 PM, "Donald S. Hall" <email@hidden> wrote:
>
Is there any way to ensure that the correct version of an app is selected
>
without having to resort to 'choose application'?
The one sure way is to to use the path to the application file. With IE in
OS X, you're in luck, since it's supplied with the OS and likes in the
Applications folder on virtually everyone's computer. You could check for
the version of the Finder, or better, whatever "computer" is now - there's
an excellent section on doing this at the AppleScript SourceBook - and then
point at the application folder and only use 'choose application' if you
come up empty. Things are actually trickier on the OS 9 side when the OS X
version wants to start up but can't, and there's nowhere so obvious to point
to.
IMO, you're going to have to use 'choose application' once, find the
hard-coded path to the file, check that it's correct (which you can do) and
save it as a property. then do the whole script in variables , with 'using
terms from', That's what i did with a script that passes data from the OS X
version of Entourage to the OS 9 version in Classic and back the other way.
You run into all sorts of weird stuff, not least that the OS 10.1.x Finder
can't deal with the 'as string' result and needs to have it coerced to
Unicode text. It also needs 'file' rather than 'alias'. You need the Finder
to check for the version (I didn't want to open the apps themselves at this
point):
if E2001 = "" then
set E2001 to choose application with title "Select Microsoft
Entourage 2001" with prompt "Select Microsoft Entourage 2001, denoted as
\"Classic Application\" (slanting E icon)" as alias
set E2001Uni to (E2001 as string) as Unicode text -- needed for AS
1.8!
tell application "Finder"
try
set theAppName to name of file E2001Uni
set v2001 to version of file E2001Uni
on error -- who knows?
set E2001Str to (E2001Uni as string)
set theAppName to name of file E2001Str
set v2001 to version of file E2001Str
end try
end tell
if theAppName "Microsoft Entourage" or v2001 does not start with
"9." then
beep 3
display dialog "Wrong application! NOT Entourage 2001." & return
& return & "You did not select Entourage 2001 when asked to." & return &
return & "Run the script again and make sure you select the \"Classic
Application\" (NOT \"Application\") with the slanting E icon when asked for
Microsoft Entourage 2001." buttons {"OK"} default button 1 with icon 0
set {E2001, EvX} to {"", ""}
return
end if
end if
if EvX = "" then
set EvX to choose application with title "Select Microsoft Entourage
X" with prompt "Select Microsoft Entourage X, denoted as \"Application\"
(new squiggly icon)" as alias
set EvXUni to (EvX as string) as Unicode text -- needed for AS 1.8!
tell application "Finder"
try
set theAppName to name of file EvXUni
set vEvX to version of file EvXUni
on error -- who knows?
set EvXStr to (EvXUni as string)
set theAppName to name of file EvXStr
set vEvX to version of file EvXStr
end try
end tell
if theAppName "Microsoft Entourage" or vEvX does not start with
"10." then
beep 3
display dialog "Wrong application! NOT Entourage X." & return &
return & "You did not select Entourage X when asked to." & return & return &
"Run the script again and make sure you select the \"Application\" (NOT
\"Classic Application\") with the new squiggly icon when asked for Microsoft
Entourage X." buttons {"OK"} default button 1 with icon 0
set {E2001, EvX} to {"", ""}
return
end if
end if
----------------------
--All that's actually done in a PREFS applet, which then loads the
_applications_ EvX and E2001 as properties into the scripts which will do
the job. (Each script needs to be able to call both versions of the app -
one after the other closes.) Getting them as applications via 'choose
application', rather than attempting to do so as aliases, and saving them
as properties, still allows the files to be moved around. Then at the
beginning of the regular running scripts, coerce the saved applications
(EvX, E2001) to string (EvXStr, Ev2001Str - which is the file path to each
version) and set a variable to the string, then use it with 'tell
application EvXStr' and 'tell application E2001Str' within 'using terms
from' blocks works perfectly. The way to get one versions to quit and the
other to open without problems turned out to be quite a puzzle, but the way
I found, getting the Finder to open the other app _as the saved application_
(E2001) , and System Prefs (or the Finder) to check or one being closed
before trying to open the other works smoothly. The important thing s
getting the Finder to open the _application_. If the version you want hasn't
finished opening, or if you try to tell 'application E2001Str' before it's
open, what happens is that the one that the file system remembers as
'application "Microsoft Entourage"' - namely the version that just closed,
EvX, opens again, or tries to. (If one is opening and the other thinks it's
being called, it gets completely stuck.) Only the Finder gets right which
is which when they're not open.
-------------------------
set EvXStr to EvX as string
set E2001Str to E2001 as string
using terms from application "Microsoft Entourage"
tell application EvXStr
activate
--- etc
end tell
end using terms from
set done to false
repeat until done
tell application "System Events" to set procs to name of every process
if procs contains {"Microsoft Entourage"} then
delay 1
else
set done to true
end if
end repeat
if procs does not contain {"Classic Support"} then
tell me
activate
display dialog "Since the Classic Environment is not currently open,
it will start up first - which will take the usual time to do so - so that
Entourage 2001 can open." buttons {"OK"} default button 1 with icon 2 giving
up after 20
end tell
end if
tell application "Finder" to open E2001 -- IMPORTANT !!
repeat until done
tell application "System Events" to set procs to name of every process
if procs does not contain {"Microsoft Entourage"} then
delay 1
else
set done to true
end if
end repeat
--wait until E2001 is open before telling it anything
set t to 0
set done to false
repeat until done
using terms from application "Microsoft Entourage"
tell application E2001Str
try
name of window 1 starts with "Entourage" --doesn't matter if
true or false, just that there's a window 1 existing
set done to true
on error
if t < 10 then -- don't get stuck more than 10 seconds
delay 1
set t to t + 1
else
set done to true
end if
end try
end tell
end using terms from
end repeat
--- some dialogs
using terms from application "Microsoft Entourage"
tell application E2001Str
--and we're off in the classic version
--
Paul Berkowitz