'application' in OS X
'application' in OS X
- Subject: 'application' in OS X
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 18 Nov 2001 22:34:45 -0800
I have spent weeks on a set of scripts, only to come adrift today on the
shoals of OS X's most peculiar and perilous handling of 'application'.
I am trying to do something perhaps not envisaged by AppleScript's
developers, but I don't see why not. I have one script running, from the OS
X Scripts menu, which needs to open, at different times, both the OS X and
Classic versions of the same app. In a separate Preferences script, I ask
the user to find each version via 'choose application'. For the script to
check whether they have done it correctly, I need to get the results 'as
alias', so that System Events or the Finder can look at the name and version
of each file. Then the aliases are set and stored as properties in the
loaded main script.
When running the main script, the part that talks to the Classic version of
the app sometimes gets stuck. Nothing happens. The script apparently has
identified 'application "Microsoft Entourage"' as the OS X version and
doesn't recognize the running Classic process as any sort of 'application
"Microsoft Entourage"'. The Finder, however, always opens the correct
version by using the alias as string, as in
tell application "Finder" to open classicApp
where classicApp is the stored alias property. No problem getting it open.
But once it's open, I can't do anything with it. Neither
tell application "Microsoft Entourage"
nor
using terms from application "Microsoft Entourage"
tell (classicApp as string)
which accesses the full application file path to the correct Classic
version, does anything. The script stalls forever, apparently waiting for
the "other' version to open up, which it won't, since the developers have
made certain that only one version can be open at a time (thank goodness)
In times past, calling on a running process was the one certain way to get
things to work. No longer. It gets worse:
In those far-off times, you could set a variable to a process in the
Finder, and set a variable to the result "as <<class psn >> " when all else
failed. Now you can't do that either:
System Events got an error: NS ReceiverEvaluationScriptError: 3
whatever that may be. Trying to be very clever:
tell application "System Events" -- or "Finder"
set theApp to application process "Microsoft Entourage"
end tell
set theApp to (theApp as <<class psn >>)
results in the lovely error:
can't make <<class pcap>> Microsoft Entourage into an application
process
with <<class psn >> compiling as 'application process'. You can't make an
application process into an application process! Evidently there are two
kinds of application process: System Events' (or the Finder's legacy) kind,
and the _real_ kind, which is inaccessible.
None of this would matter if I could coerce
set theApp to choose application as application
(which variable works perfectly in the main script as a tell block) to alias
in the prefs script, and elsewhere as needed. But I can't. It won't coerce
to anything normal.
Evidently the script has identified 'application "Microsoft Entourage"' in
all its guises as the OS X version. And 'choose application' can pinpoint
the Classic version and set it as an alias or as an application, but not
both. But then I'm stuck: if I've set it 'as application', I _have_ to open
it to use it. And I'm not too confident about saving an 'application' as a
property in another script anyway.
Is there any way to find the application file or alias from the
'application' type? Or some real way to open the correct version of the
application from the alias or file path? This roadblock feels ridiculous.
--
Paul Berkowitz