Re: Scripting the "Mail' application to add attachments
Re: Scripting the "Mail' application to add attachments
- Subject: Re: Scripting the "Mail' application to add attachments
- From: Evan Gross <email@hidden>
- Date: Thu, 20 Sep 2001 02:33:26 -0400
On 9/19/01 2:36 PM, "Rosyna" <email@hidden> wrote:
>
I had the same problem, the scripting dictionary offers no way to add
>
an attachment to a message. Instead of leaving mail out, I just
>
decided to leave adding attachments out of my app.
>
>
Ack, at 9/19/01, Steven Lobo said:
>
>
> I'm working on a Carbon application which performs some image processing on
>
> an Image file and has the capability to transfer this processed file to
>
> other applications using Apple Events. This feature works fine for most Mac
>
> OS X applications. But on the Mac OS X 'Mail' application, I can only open
>
> the mail application if it isn't open already. The image file is not added
>
> to the compose window as an attachment. This feature works fine for other
>
> mailing applications like the 'Eudora 5.1 (OS X)' mail application.
>
>
>
> I plan to write a script to implement this feature. Has anybody already done
>
> this, or has an idea ass to how to perform this?
>
Steven (and Rosyna),
There is a way to add attachments to a new message you've created (not sure
about an existing Draft message) using AppleScript (Rosyna, you should have
asked - Stuffit Express can send messages with attachments via Mail.app!).
You have to look at the Text Suite to figure out how to deal with
attachments, you won't find it in Mail.app's dictionary. But (at least in
10.0.4) Mail.app acts a little odd when you add attachments - mainly w.r.t.
where it places the icons representing the attachments in the message body.
The basic snippet I use is (inattachments is a list of aliases, sent to the
AppleScript as a parameter to a subroutine I call) as follows:
(excuse the word wrapping, and hopefully I have the terms correct because
I'm not in OS X right now and am looking at an AppleScript with raw event
codes)
-- Attachments. Have to add them in reverse order because (as of 10.0) "end
of" doesn't
-- seem to be supported in Cocoa apps properly yet.
repeat with anattachment in (reverse of inattachments)
tell content of thenewmessage to make new text attachment with
properties {filename:anattachment} at before the first word
end repeat
I also found that the new message "looks better" if I set the text of the
message body after creating the attachments:
-- Subject and message body.
set subject of thenewmessage to insubject
tell content of thenewmessage to make new text with data inbody & return at
before the first word
Hope this helps, hopefully you can get things working. If you have other
questions, fire away.
And if anyone can tell me how to save a newly-created message as a Draft
*without* Mail.app asking whether I should save changes (i.e. close window 1
saving yes/no behaves like "ask" - always asking - obviously a bug) let me
know!
Evan Gross
Rainmaker Research Inc.