Re: Double Tell and Outlook...possible?
Re: Double Tell and Outlook...possible?
- Subject: Re: Double Tell and Outlook...possible?
- From: JollyRoger <email@hidden>
- Date: Thu, 30 Aug 2001 08:01:11 -0500
On 8/30/2001 3:32 AM, "Guy Parker" <email@hidden> wrote:
>
I'm trying to write a Script that will control either Outlook Express or
>
Entourage (with common code) depending upon what's installed on the machine
>
running the Script. Since the two application's dictionaries are identical
>
(at least for the functions I need to use) I figure this should be possible
>
without writing two different versions.
>
>
I've tried the "double tell" technique but Outlook seems to be one of those
>
applications where this option won't work (maybe it has a "dynamic"
>
library?).
>
>
I wondered if the new "using terms from" capability would help but have had
>
no success...anyone know a good source of examples/documentation for this?
>
>
In the Script below the line "set MessageWindow to front window" generates
>
an event of "get window 1 of application "Outlook Express"" that produces an
>
error. But without the double tell the event is just "get window 1" which
>
works.
>
>
Can anyone think of clever changes that could make this work or an entirely
>
different approach to the same goal?
(snip)
You don't need to do all that. It's much simpler and easier to just check
to see whether the app that is calling your script is Entourage or Outlook
Express. Once you determine which it is, store the name and creator in a
property. In your script, you can either just blindly address the
application like so:
-- method 1
tell application gCallerName
using terms from application "Outlook Express"
-- some OE command
end using terms from
end tell
Or if the syntax for the command you want to use has changed in Entourage,
you can check the creator property to determine which app you need to
address like so:
-- method 2
if gCallerCreator = kOutlookExpressCreator then
tell application gCallerName
using terms from application "Outlook Express"
-- some OE command
end using terms from
end tell
else if gCallerCreator = kEntourageCreator then
tell application gCallerName
using terms from application "Microsoft Entourage"
-- some Entourage command with different syntax here
end using terms from
end tell
end if
Method 2 strikes me as being a bit more safe; but either should work fine
for most cases.
Here's a simple illustration. If the comments aren't enough, and you have
questions, feel free to ask:
-- begin script
-- constants
property kOutlookExpressCreator : "MSNM"
property kEntourageCreator : "OPIM"
-- filled in at initialization
property gCallerPath : "n/a" -- path to the calling application
property gCallerName : "n/a" -- file name of the calling application
property gCallerCreator : "n/a" -- creator code of the calling application
property gCurrentIdentity : "n/a"
-- figure out who called us
-- when the script runs under Entourage/Outlook Express, me points to
-- the calling application
set gCallerPath to (path to me) as text
set gCallerName to my FilenameFromPath(gCallerPath)
set gCallerCreator to file creator of (info for (gCallerPath as alias))
-- now we can call either app using terms from Outlook Express
-- method 1
tell application gCallerName
using terms from application "Outlook Express"
set gCurrentIdentity to name of the current identity
end using terms from
end tell
-- method 2
-- get current identity name (method 2)
if gCallerCreator = kOutlookExpressCreator then
tell application gCallerName
using terms from application "Outlook Express"
set gCurrentIdentity to name of the current identity
end using terms from
end tell
else if gCallerCreator = kEntourageCreator then
tell application gCallerName
using terms from application "Microsoft Entourage"
set gCurrentIdentity to name of the current identity
end using terms from
end tell
end if
display dialog "The current identity is \"" & gCurrentIdentity & "\""
on FilenameFromPath(thePath)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 1
else
set idx to -1
end if
set folderName to item idx of pathAsList
set AppleScript's text item delimiters to saveDelim
return folderName
end FilenameFromPath
-- end script