AppleScript Inquiry

T

Thomas

We are using a 3rd-party software application on a system running Leopard
v10.5.2. The following script is one of a number of scripts that are part of
this application:

<http://home.comcast.net/~tyh/OMScript.jpg>

When this script is run, the application invokes Apple's "Mail" program and
attaches images as an attachment, however we have a need to change the
script to invoke "Entourage" instead of "Mail". Our request is fairly
basic -we are seeking instructions on what line(s) to change (tell
application "Mail" ??), especially the code which relates to setting the
attachments via Entourage? Once we modify the script, is re-compiling
required prior to placing it back into commission, and how do we do this?

Thank you in advance to all who offer their advice and expertise.
 
W

William Smith

Thomas said:
We are using a 3rd-party software application on a system running Leopard
v10.5.2. The following script is one of a number of scripts that are part of
this application:

<http://home.comcast.net/~tyh/OMScript.jpg>

When this script is run, the application invokes Apple's "Mail" program and
attaches images as an attachment, however we have a need to change the
script to invoke "Entourage" instead of "Mail". Our request is fairly
basic -we are seeking instructions on what line(s) to change (tell
application "Mail" ??), especially the code which relates to setting the
attachments via Entourage? Once we modify the script, is re-compiling
required prior to placing it back into commission, and how do we do this?

Thank you in advance to all who offer their advice and expertise.

Hi Thomas!

You can use something like this (three lines):

tell application "Microsoft Entourage"
set theMessage to make new outgoing message with properties
{subject:"This is your file", content:"Attached is your file.",
recipient:{address:{address:"[email protected]", display name:"I. M.
Somebody"}}, attachment:alias pathToFile}
send theMessage
end tell

I suggest you invest in Paul Berkowitz's VBA to AppleScript transition
guide <http://www.mactech.com/vba-transition-guide/>. It is brimming
with AppleScript code for all Office product and only costs $9.95.

As for recompiling, yes, you need to recompile but this is done
automatically as you're saving.

Hope this helps!

--

bill

William M. Smith, Microsoft Interop MVP - Mac/Windows
Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
 
T

Thomas

William,

Thank you for the advice and code.

(1) another user suggested the following script - do you think that this
script is a valid alternative (I'm not sure if they are familiar with
invoking attachments in Entourage:

on open theList
set theList to ""
set SendFileList to {""}
repeat with anItem in theList
set SendFileList to SendFileList & {anItem as alias}
end repeat
set SendFileList to "Cassandra:Users:masahiro_takeda:desktop:test1.txt" as
alias
tell application "Microsoft Entourage"
activate
set newMessage to make new draft window with properties {to
recipients:"email to @ whom ever", subject:"test mail"}
make new attachment at newMessage with properties {file:SendFileList}
end tell
end open

(2) your code includes the line "send theMessage"; this script is being used
with a photo program, the user chooses their photos from a list and then
clicks a button to start the script; all we want the script to do is load
Entourage and attach the selected photos to a blank email message, we don't
want the script to send the message, just to end at this point and then
leave it up to the user to add text to the message body and send on their
own

(3) lastly, are you saying that the original code from our initial inquiry
includes unneccessary lines in order to perform the task as described in
(2), and that your three lines of code is all that is required (+/- the
"send theMessage" line)

Thomas
 
W

William Smith

Hi Thomas!

My comments are inline with yours...
William,

Thank you for the advice and code.

(1) another user suggested the following script - do you think that this
script is a valid alternative (I'm not sure if they are familiar with
invoking attachments in Entourage:

It very well could work. You'd need to copy the text and paste it into
the Script Editor found in /Applications/AppleScript, save it as an
application and then test it.
(2) your code includes the line "send theMessage"; this script is being used
with a photo program, the user chooses their photos from a list and then
clicks a button to start the script; all we want the script to do is load
Entourage and attach the selected photos to a blank email message, we don't
want the script to send the message, just to end at this point and then
leave it up to the user to add text to the message body and send on their
own

I wasn't trying to rewrite your original code but rather show you the
syntax of composing a basic message with E-mail address, subject, body
text, attachment and how to send.
(3) lastly, are you saying that the original code from our initial inquiry
includes unneccessary lines in order to perform the task as described in
(2), and that your three lines of code is all that is required (+/- the
"send theMessage" line)

It looks fairly simple to me and if it works for you then I wouldn't be
concerned about how compact it is unless it's dozens of lines long.

AppleScript is easy to read but not always easy to write. I'm usually a
proponent of showing somebody *how* to do something rather than doing it
for them but if the other script meets your needs then by all means run
with that.

Hope this helps!

--

bill

William M. Smith, Microsoft Interop MVP - Mac/Windows
Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
 
T

Thomas

Bill,

Apologies in advance for our lack of experience in this area, but we tried
what you suggested and 5 variations of the original script without success
(see actual scripts below):

Script 1 - Entourage launches successfully, but no new message is created

Script 2 - Entourage launches successfully, but script error pops up "The
variable pathToFile is not defined"

Script 3 - script does not even launch

Script 4 - Entourage launches successfully, but no new message is created

Script 5 - script does not even launch

Again, this is a photo program where we select one or a number of images and
then press the email option. At this point, the script should start by
opening Entourage and attaching the image(s) to a blank email; the script
should then end and allow the user to add text, title, recipient, send the
message.

We are seeking further guidance. Thank you.

Thomas

--------------------

Script1

on open theList

set SendFileList to {""}
repeat with anItem in theList
set SendFileList to SendFileList & {anItem as alias}
end repeat


tell application "Microsoft Entourage"
activate
set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat
end tell
end open

--------------------

Script2

on open theList

set SendFileList to {""}
repeat with anItem in theList
set SendFileList to SendFileList & {anItem as alias}
end repeat


tell application "Microsoft Entourage"

activate
set theMessage to make new outgoing message with properties {subject:"This
is your file", content:"Attached is your file.",
recipient:{address:{address:"[email protected]", display name:"I. M.
Somebody"}}, attachment:alias pathToFile}
end tell
end open

--------------------

Script3

on open theList

set theList to ""
set SendFileList to {""}
repeat with anItem in theList
set SendFileList to SendFileList & {anItem as alias}
end repeat

set SendFileList to "Cassandra:Users:masahiro_takeda:desktop:test1.txt" as
alias

tell application "Microsoft Entourage"
activate
set newMessage to make new draft window with properties {to
recipients:"email to @ whom ever", subject:"test mail"}
make new attachment at newMessage with properties {file:SendFileList}
end tell
end open

--------------------

Script4

on open theList

set SendFileList to {""}
repeat with anItem in theList
set SendFileList to SendFileList & {anItem as alias}
end repeat


tell application "Microsoft Entourage"

-- set SendFileList to {"Cassandra:Users:masahiro_takeda:desktop:test.txt"
as alias}
-- set SendFileList to {"Cassandra:Users:masahiro_takeda:desktop:test1.txt"
as alias} & SendFileList

activate
set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat
end tell
end open

--------------------

Script5

on open theList
tell application "Microsoft Entourage"
activate
set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat
end tell
end open
 
T

Thomas

Bill,

This issue is on an Intel-based Mac running v10.5.2 running Entourage
v12.0.1. We were missing the crucial step of re-saving the script as an
"Application" under SaveAs. With this correction, one of our original
scripts does load up Entourage, but it still does not launch a new message
and attach images (not sure why this one doesn't work with our
configuration - let us know if you have any tips on how to correct this
script):

on open theList
tell application "Microsoft Entourage"
activate
set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat
end tell
end open

However, we re-saved another script and it loads up Entourage, loads new
draft message, and attaches all images:

on open tList
tell application "Microsoft Entourage"
activate
set nMessage to make new draft window with properties {to
recipients:"[email protected]"}
repeat with i in tList
make new attachment at nMessage with properties {file:i}
end repeat
end tell
end open

Thank you for all the effort you put into helping us with this dilemma.

Thomas
 
T

Thomas

The photo program utilizes this AppleScript to send images via
email. This application is running on an Intel-based Mac running v10.5.2
with Entourage 2008 v12.0.1. The following script successfully launches
Entourage, loads up a new draft message, and attaches all images perfectly:

on open tList

tell application "Microsoft Entourage"
activate

set nMessage to make new draft window with properties {to
recipients:"[email protected]"}
repeat with i in tList
make new attachment at nMessage with properties {file:i}
end repeat

end tell

end open


However, one of our alternative scripts launches Entourage 2008, but it does
not launch a new message or attach the images. This script was written for
and works on Entourage 2004 (11.4), OS v10.4.11, but not on the system
running Entourage 2008:

on open theList

tell application "Microsoft Entourage"
activate

set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat

end tell

end open

Looking for suggestions on how to correct the second script so it will
execute completely on Entourage 2008. Thank you again.
 
W

William Smith

Thomas said:
However, one of our alternative scripts launches Entourage 2008, but it does
not launch a new message or attach the images. This script was written for
and works on Entourage 2004 (11.4), OS v10.4.11, but not on the system
running Entourage 2008:

on open theList

tell application "Microsoft Entourage"
activate

set newMessage to (make new outgoing message)
repeat with aFile in theList
make new attachment at newMessage with properties {file:aFile as alias}
end repeat

end tell

end open

Looking for suggestions on how to correct the second script so it will
execute completely on Entourage 2008. Thank you again.

Hi Thomas!

Saved scripts essentially *remember* the applications they were compiled
for. Open the script on your new machine with Entourage 2008 and resave
it there. That will probably correct your opening issue.

Hope this helps!

--

bill

William M. Smith, Microsoft Interop MVP - Mac/Windows
Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
 
W

William Smith

Thomas said:
Bill,

This issue is on an Intel-based Mac running v10.5.2 running Entourage
v12.0.1. We were missing the crucial step of re-saving the script as an
"Application" under SaveAs. With this correction, one of our original
scripts does load up Entourage, but it still does not launch a new message
and attach images (not sure why this one doesn't work with our
configuration - let us know if you have any tips on how to correct this
script):

Hi Thomas!

I believe the problem you're seeing is that you're trying to make a new
Outgoing message but then act on it later in the script. An Outgoing
message needs to be created in one fell swoop with the subject, body,
address, attachments, etc.

Have a look at the example snippet I provided earlier and I still
recommend looking through Paul Berkowitz's transition guide for all
sorts of examples of what you can do.

--

bill

William M. Smith, Microsoft Interop MVP - Mac/Windows
Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
 
Top