AppleScripting Attachments in Entourage

G

Guest

Hi gang,

I'm using Microsoft Office 2004 and I know nothing about AppleScript,
but I was wondering if someone could help me finish this AppleScript?
I spent about 4 hours trying to figure this out so far, but I can't
figure out how to add an attachment to this.

Basically, I know the filepath to the file I want to attach... for the
sake of example, let's say the filepath location is:
"My Hard Drive/Users/scott/Desktop/invoice.pdf"

Any ideas how to finish this script? Thanks!

(By the way, the reason I'm using an AppleScript instead of using
FileMaker 8's built-in ability to attach a PDF to an outgoing email is
that there's an annoying bug that has always been in Entourage where it
does NOT open up & display a new outgoing message created by FileMaker
-- it only puts the email in either the outbox or the drafts folder.
This is NOT accurate nor desired behavior -- Apple's Mail program does
this properly.)

Here's the AppleScript I've got so far:


tell application "FileMaker Pro Advanced"
set emailaddress to cell "Email Address" of current record
set MailSubject to "Invoice"
end tell
tell application "Microsoft Entourage"
set MyMessage to make new outgoing message with properties
{recipient:emailaddress, subject:MailSubject}
open MyMessage
activate
end tell


Thanks,
Scott
 
G

Guest

There was a typo in my filepath... I meant for it to say:

"My Hard Drive/Users/scott/Desktop/invoice.pdf"
 
G

Guest

Thanks, Matt!

With your help, I was able to figure out the following AppleScript
which works in FileMaker Pro 7 & FileMaker Pro 8, for sending an email
with attachments in Entourage X or Entourage 2004. This was tested on
Mac OS X 10.4.2, and the beauty of this AppleScript (instead of using
FileMaker 8's built-in ability to send emails) is that this AppleScript
will actually leave the email message open in Entourage for you to edit
-- and bring it to the foreground -- instead of leaving it in the
"drafts" folder, which is what will happen when you use the function
natively in FileMaker Pro.

Here is the final AppleScript:


tell application "FileMaker Pro Advanced"
set emailaddress to cell "Email Address" of current record
set MailSubject to cell "Invoice" of current record
set f to "Macintosh HD:Users:scottworld:Desktop:scottworld.pdf"
end tell
tell application "Microsoft Entourage"
set MyMessage to make new draft window with properties
{recipient:emailaddress, subject:MailSubject}
tell MyMessage
make new attachment at beginning with properties {file:f}
end tell
activate
end tell
 
G

Guest

Actually, even better is this:

If you have already set the script variables in FileMaker Pro, you
could just perform the Microsoft Entourage portion of this by writing a
calculated AppleScript that looks like the following:

"tell application \"Microsoft Entourage\"" & "¶" &
"set MyMessage to make new draft window with properties {recipient:\""
& $emailaddress & "\", subject:\"" & $subject & "\"}" & "¶" &
"tell MyMessage" & "¶" &
"make new attachment at beginning with properties {file:\"" &
$filepath_applescript & "\"}" & "¶" &
"end tell" & "¶" &
"activate" & "¶" &
"end tell"

$emailaddress, $filepath_applescript, and $subject are all script
variables that were set in ScriptMaker.

Note that the file path for AppleScripts is different than the file
path that FileMaker Pro yields, because AppleScript file paths contain
colons :)) instead of slashes (/), and they can NOT start with any
punctuation. So I used this script step to set the variable for the
AppleScript-native file path (when given a normal file path of
$filepath):

$filepath_applescript =

Let ( $text = Substitute ( $filepath ; "/" ; ":" );

Middle ( $text ; 2 ; Length($text) - 1 )

)
 
M

matt neuburg

Note that the file path for AppleScripts is different than the file
path that FileMaker Pro yields, because AppleScript file paths contain
colons :)) instead of slashes (/), and they can NOT start with any
punctuation. So I used this script step to set the variable for the
AppleScript-native file path (when given a normal file path of
$filepath):

$filepath_applescript =

Let ( $text = Substitute ( $filepath ; "/" ; ":" );

Middle ( $text ; 2 ; Length($text) - 1 )

)

That is not at all a reliable approach, for many reasons. I was not
aware that FileMaker used POSIX paths now, but in any case AppleScript
has a way to convert a colon-delimited path to a POSIX path or vice
versa and you are better off using this if FileMaker doesn't provide
one. If you have a valid POSIX path f then ask AppleScript for posix
file f (instead of file f). I hate to sound like an ad, but you really
should learn the language if you're going to use it, instead of
scrabbling in the dark like this, and my .sig tells you one way to do
so. m.
 
G

Guest

Hi Matt,

Thanks for the heads-up on your AppleScript book! I will definitely
check it out!!

I tried to do what you said with the POSIX file path, but it didn't
work for me I'll try to troubleshoot this more later. I'm gonna try
to figure this out on my own.

Since you are the AppleScript guru, here's one final question f have
for you that seems to effect ANY AppleScript that triggers an outgoing
email message in Entourage, not just this particular one that we've
been working on:

When you're manually typing up a new email message in Entourage, and
you start entering someone's email address, Entourage does sort of a
"reverse lookup" from your Entourage address book and fills in their
First & Last Name in the "to" field (based on the email address that
you were just typing).

But when you trigger an outgoing message via an AppleScript, Entourage
doesn't even try to lookup the address that you have placed in the "to"
field. It just sends the message, addressed to the person's email
address, but you never get the person's First Name & Last Name embedded
into the "to" field.

Not a huge deal, but if you're searching through the "to" fields in
your "Sent Items", all of your email messages are no longer consistent.


Is there any way to trigger this "lookup" via AppleScript also?

Thanks again!

Sincerely,
Scott
 
P

Paul Berkowitz

Thanks for the heads-up on your AppleScript book! I will definitely
check it out!!

I tried to do what you said with the POSIX file path, but it didn't
work for me I'll try to troubleshoot this more later. I'm gonna try
to figure this out on my own.

Since you are the AppleScript guru, here's one final question f have
for you that seems to effect ANY AppleScript that triggers an outgoing
email message in Entourage, not just this particular one that we've
been working on:

When you're manually typing up a new email message in Entourage, and
you start entering someone's email address, Entourage does sort of a
"reverse lookup" from your Entourage address book and fills in their
First & Last Name in the "to" field (based on the email address that
you were just typing).

But when you trigger an outgoing message via an AppleScript, Entourage
doesn't even try to lookup the address that you have placed in the "to"
field. It just sends the message, addressed to the person's email
address, but you never get the person's First Name & Last Name embedded
into the "to" field.

Not a huge deal, but if you're searching through the "to" fields in
your "Sent Items", all of your email messages are no longer consistent.


Is there any way to trigger this "lookup" via AppleScript also?


AppleScript has no access to the "MRU list" (most recently used) list, but
it does have access to the Entourage Address Book, and can look up contacts
there. There's also nothing stopping you from entering both a display name
and email address literally, in various ways. If we stick just with draft
windows for the moment (new message windows on-screen), you can write to
Matt this way:

set to recipients to "Matt Neuburg <[email protected]>"

If the display name contains any punctuation (like a middle initial), you
need to put it inside quotes, escaped as usual for AppleScript:

set to recipients to "\"Joe E. Blow\" <[email protected]>"

(and it's perfectly all right to do it even without punctuation, so if you
ever do this for unknown names retrieved from elsewhere, always use the
quotes).

Incidentally, you don't have to add in items bit by bit after making the
draft window. You can do it all at once at the moment of creation:


set f to alias ((path to desktop as string) & "hacienda map.pdf")
tell application "Microsoft Entourage"
make new draft window with properties {to recipients: "Matt Neuburg
<[email protected]>", attachment:{file:f}, subject:"howdy"}
end tell


(I.e. you can treat 'attachment' as if it were a property for these
purposes. You can even include a list of several attachments this way.)

But I digress. To "look up" a contact use the 'find' command. If you have
entered Matt as a contact in your address book, then:

set cc to find "(e-mail address removed)"

That will actually get you a list of contacts ­ since you could have more
than one entry (perhaps two people in the same family) with the same email
address. But usually there's just one, so it's generally safe to

try
set c to item 1 of (find "(e-mail address removed)")
on error
beep
display dialog "There's no contact with that email address."
return
end try

What good is this? Just in case you don't know someone's full name offhand
you could look him up this way, and get the name from the contact:

set eAddress to "(e-mail address removed)"
set c to item 1 of (find eAddress ) -- try/error, etc. as above
set dName to display name of c -- contact inherits form 'address'
class
make new draft window with properties {to recipients:(dName & " <" &
eAddress & ">"), attachment:{file:f}, subject:"howdy"}

It will even display the contact "blob icon".

Another way, using the syntax from outgoing message, will also work here,
with shortcuts since you're only writing to one recipient, and it's the
default recipient type (to recipient) which doesn't need to be specified:

make new draft window with properties {recipient:{display
name:dName, address: eAddress}, attachment:{file:f}, subject:"howdy"}

Here 'recipient' is also being used as a property (rather than an element,
as it should be by rights).

I've used variables (except for subject) so you can see how to make an
all-purpose script where you just enter the email address you want at the
beginning for eAddress, and the rest takes care of itself.


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top