If I have an email selected and want to open the attachment with the
default program how would I go about this.
I tried the following:
tell application "Microsoft Entourage"
set the_message to item 1 of (selection as list)
get attachment of the_message
end tell
I've also tried return attachment, open attachment, but none seem to
work.
Also, is there a scripting guide for entourage?
The answer to both questions is that you need to study the Entourage
AppleScript dictionary to understand the "object model". There is no
separate AppleScript Guide - partly because Entourage AppleScript has been
around ever since the beginning (and earlier, it was based on the Outlook
Express implementation) and it is - mostly - quite orthodox and
straightforward AppleScript, unlike the rest of Office. (And the Guides for
Word, Excel and PowerPoint are mostly "translations" from the pre-existing
VBA Help for those apps.) One would be useful, of course, especially for
those unusual and special things that crop up from time to time.
One of those things is 'selection'. It is one of a very few properties
('selection' is a property of the 'application' class in the dictionary) in
Entourage (there are far more in the other Office apps. and also in almost
all of Apple's own apps) that require the explicit 'get' if accessed all in
one line:
set the_message to item 1 of (get selection)
Alternately you can use a variable to evaluate, and a second line:
set sel to selection
set the_message to item 1 of sel
I use the first method myself, and save a line.
However, you should realize that in Entourage, the selection can be either a
list (of messages, contacts, tasks, etc.) or it can be text (in a message,
note, event window, etc.), or nothing at all ('get selection' errors),
depending on which window is frontmost and which bit of the main window
(message list or previewed message) is in focus. So it's not so reliable. If
it's already from a list, even if just one item (message, contact, etc.) is
selected, you don't need 'as list'. And if it's text, coercing it a list is
not going to help you here.
Better than 'selection' in this case is the property 'current messages' -
which you'll find in the 'application' object of the dictionary. That means
"selected messages" even if there's a message window in front, or even if
some text is also selected in the previewed message, and even if the
message, not the list, is in focus. 'current messages' is another (the
other) property needing the explicit 'get'. So here's what you should use as
your first line:
set the_message to item 1 of (get current messages)
(Note that you use the very same line to specify the message being filtered
automatically by a Rule, which is extremely useful. You can this test your
script on a selected message, and then run it automatically from a rule.
'selection' will NOT work for a script run from a rule - only 'current
messages' will do.)
OK, so how about 'attachment'? Well, if you look at 'message' (or, better
yet, 'incoming message', since I think you're discussing an attachment to a
message you received?), you'll see that 'attachment' is _not_ a property,
but an element. If you don't know what that means, you need to first learn
AppleScript. Even a simple guide such as 'Applescript: The Missing Manual'
will explain this syntax. Basically, an element is something that an object
can have zero or any number of, while a property is always just one thing,
one attribute, that it must have (even if empty). If you think about it a
moment, you'll see that 'attachment' must be an element, since a message can
have none to any number. So what you want is this:
set all_attachments to every attachment of the_message
set first_attachment to item 1 of all_attachments
(although you might want to consider what you want to do if there's more
than one. You might be able to send a command to all at once - otherwise
you'd need a repeat loop to cycle through each one. If you know for certain
that there will only ever be one attachment, you could instead do:
set the_attachment to attachment 1 of the_message
Check 'attachment' in the dictionary to see what properties you can access.
You can also save attachments to disk. If that's what you want to do, note
that you 'save' (in Standard Suite) each one 'at' a file location you can
specify, as text. You use the whole colon-delimited path (colons between
folders) as text. (You can try to save it 'at' a folder instead, but there
can be problems if you do that.) If you specify the file location, and want
to use the name of the attachment as the name of the file (plus perhaps an
extension), note that you'll need a routine for substituting a "-" or other
character for any ":" colon that might be in the attachment name, since
colons are illegal in Mac file names when specifying as file paths.
Note also that when _making_ an attachment to an outgoing message or draft
window, you can specify it as if it were a property, rather than go through
the whole hullabaloo of making it as an element. This is a kind of
"shorthand" Entourage allows, and it's not documented anywhere! This is
something that really should be in a Guide. It's particularly useful when
making several attachments: they can all be entered as a list. If you need
to know more about this, do ask. But it doesn't come into your situation
here. I only mention it in case you've seen an example of 'attachment' being
specified in a record of properties when making a new message, and that's
why (naturally enough) you may have thought that you could get the
'attachment' property of an existing message. You can't. You have to get it
as an element. When in doubt, always follow the dictionary literally.
--
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.