Re: Multi application support in single script [part 1 of 2]
Re: Multi application support in single script [part 1 of 2]
- Subject: Re: Multi application support in single script [part 1 of 2]
- From: Kai <email@hidden>
- Date: Sat, 28 Jun 2003 15:21:30 +0100
on Sat, 28 Jun 2003 00:36:33 +0200, CasBaH Software wrote:
>
I am trying to build an AppleScript (for Mac OS X) that supports
>
several clients providing the same service - but with mixed luck.
>
What I'm trying to do is to support different email applications in the
>
same script, but the applications referenced in the script might not be
>
installed on all computers running the script. For now I have
>
implemented the wanted functionality for Mail, Entourage, Eudora, and
>
Mailsmith. When I run my script and e.g. Eudora is not launched it will
>
be launched by my script.
That's because, when you compile your script, it remembers the path to the
Eudora application file. (This won't necessarily help if the script is run
on another machine.)
>
I have also gotten reports from users without Entourage installed that the
>
script asks for Entourage.
If it contains an explicit <tell application "XYZ"> block then your script
will want to know the location of the "XYZ" file - so that it can be prepare
to er... tell it stuff. (If "XYZ" is a running process, then your script can
get the location information it needs from that.)
You can get around this by using an implicit tell block:
--====================
set appName to "XYZ"
tell application appName
--do stuff
end tell
--====================
This way, the script won't check for the app unless and until the relevant
tell statement is encountered at run-time.
However, you'll now find that you have a problem getting the script to
understand application-specific keywords - which will cause it to refuse to
compile. For example, try compiling this:
--=======================
set appName to "Finder"
tell application appName
disk 1's name
end tell
--> compile error
--=======================
You can get around this by introducing a 'using terms from' block, like
this:
--=======================
set appName to "Finder"
using terms from application "Finder"
tell application appName
disk 1's name
end tell
end using terms from
--> "Macintosh HD"
--=======================
...which should then both compile and run as required.
>
I thought I had solved this problem by checking that said application
>
is running at the time of running the script - see enclosed script
>
snippets.
>
>
Is it not possible to create this kind of AppleScript? Must I create a
>
separate script for each email client?
Not necessarily.
Before we look at your script, perhaps I should briefly mention that you can
check for the presence of non-running applications - as long as you know
their 4-character application file id. If you're not sure about the id, use
something like this to check the relevant app:
--=======================================
(info for (choose file))'s file creator
--> "MACS" [application chosen: Finder]
--=======================================
Once you have the relevant id codes, you can do something like this:
-------------------------------------------------------
(Any wrapped lines abutting the left edge of the window
should be reconnected to the end of the previous line)
-------------------------------------------------------
--=============================================
property appIDList : {"XXXX", "YYYY", "ZZZZ"}
property appAliasList : {}
to getApps()
tell application "Finder" to repeat with appID in appIDList
try
set appAliasList's end to application file id appID as alias
end try
end repeat
end getApps
if appAliasList is {} then getApps()
if appAliasList is {} then display dialog "No supported application is
available." buttons {"Cancel"} default button 1 with icon 0
set tgtApp to appAliasList's item 1 as string
tell application tgtApp
activate -- or whatever
end tell
--=============================================
You'll notice that, in this case, the value of the variable 'tgtApp' is
actually a filepath - rather than just a name. This is just as usable as a
filename, but the form is simply:
--===============================================
tell application "path:to:required:application"
--===============================================
(Because it's more specific, this method can also help to avoid confusion if
there's more than one copy/version of an app on disk.)
[please also see part 2 of this message...]
--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.