Re: Saving Entourage Attachments
Re: Saving Entourage Attachments
- Subject: Re: Saving Entourage Attachments
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 25 Nov 2001 18:26:13 -0800
On 11/25/01 5:44 PM, "Jason Bourque" <email@hidden> wrote:
>
Anyone care to share code on this?
>
>
>
Thanks, Frustration at it's best.
Making attachments, or saving them to disk?
Making:
set theFile to alias "Your HD:A Folder:A File"
--set theFile to alias ((path to desktop as string) & "A File")
tell application "Microsoft Entourage"
set theMsg to item 1 of (get current messages)
-- or in a new draft window:
--set theMsg to window 1
make new attachment at theMsg with properties {file:theFile}
end tell
Or if you prefer:
make new outgoing message at drafts folder with properties
{subject:"foo", recipient:{address:{address:"email@hidden", display name:"Joe
Bar"}}, attachment:{file:theFile}}
Not too hard, was it? It's a little more complicated setting a list of files
as multiple attachments. Basically, get your list of aliases and then set up
a list of {file:alias "something"} records inside an Entourage tell block
(it always has to be inside because of that 'file' keyword belonging to
Entourage. You can do it by repeat loop. In OS X, you have to put any
variable representing an alias file path outside the tell block (or use
'tell me') for peculiar OS X reasons I know not. In a new message, you can
put the whole list into the attachment label:
set theAttachments to {}
repeat with theFile in theFiles -- a list of aliases
set end of theAttachments to {file:theFile}
end repeat
tell application "Microsoft Entourage"
make new outgoing message at drafts folder with properties
{subject:"foo", recipient:{"Joe Bar <email@hidden>"}, attachment:
theAttachments}
end tell
[with an easier way to make a single To recipient, not n the dictionary]
Saving:
set fileSpec to "HD:A Folder:A File" -- must be string!
tell application "Microsoft Entourage"
set theMsg to item 1 of (get current messages)
set theAttachment to attachment 1 of theMsg
set theFile to save theAttachment in fileSpec
end tell
Although the Dictionary says that you save it in alias, you don't. (it's
Apple's error - most apps have this error in the Standard Suite, taken over
from Apple's SDK). You save it in a string, it is coerced to a file spec,
and the result is an alias. (In other apps you can save it in file
specification, but that won't work in Entourage or OE because they have
their own 'file' keyword meaning something else.) You _can_ save it 'in' a
folder using 'alias', but then you can't set a variable to it, so the above
way is much better. It works also in OS X, where Apple has changed the file
type but string will still coerce to alias. (And some of the dictionaries
have it correct now, including Entourage.)
--
Paul Berkowitz