Re: Scripting Bridge and multiple attachments
Re: Scripting Bridge and multiple attachments
- Subject: Re: Scripting Bridge and multiple attachments
- From: has <email@hidden>
- Date: Tue, 1 Sep 2009 22:44:17 +0100
On 1 Sep 2009, at 11:29, email@hidden wrote:
Israel Chauca Fuentes wrote:
I'm using scripting bridge to send emails with Mail.app and I have
managed to do so, but I still have a little problem.
When adding attachments, the first one is placed at the beginning of
the message, while the rest of them are placed at the end of the
message, which is certainly odd. I would like to place all attachments
at the end of the message, which is how I use to place them by hand,
but I don't know how.
Works in AppleScript:
property linefeed : character id 10
set the_paths to {"/path/to/image1.jpg", "/path/to/image2.jpg"}
tell application "Mail"
set msg to make outgoing message ¬
with properties {subject:"test", content:"test test",
visible:true}
make new paragraph at end of content of msg with data linefeed &
linefeed
repeat with path_ref in the_paths
make new attachment at end of paragraphs of content of msg ¬
with properties {file name:path_ref}
end repeat
end tell
With objc-appscript, it'd be something like this (untested code and
without error handling added; I just ran the above AppleScript through
ASTranslate and tidied the result a bit):
#import "MLGlue/MLGlue.h"
MLApplication *mail = [MLApplication applicationWithName: @"Mail"];
MLMakeCommand *cmd = [[[mail make]
new_: [MLConstant outgoingMessage]]
withProperties: [NSDictionary dictionaryWithObjectsAndKeys:
@"test text", [MLConstant
content],
ASTrue, [MLConstant visible],
@"test subject", [MLConstant
subject],
nil]];
MLReference *msg = [cmd send];
[[[[[mail make] new_: [MLConstant paragraph]]
at: [[msg content] end]]
withData: @"\n"] send];
for (path in paths) {
cmd = [[[[mail make] new_: [MLConstant attachment]]
at: [[[[msg content] paragraphs] at: -1]
after]]
withProperties: [NSDictionary dictionaryWithObject: path
forKey: [MLConstant
fileName]]];
[cmd send];
}
Scripting Bridge imposes all sorts of restrictions on how object
specifiers and events can be constructed via glues, so I suspect the
only way you could do it there is by messing around with raw AE codes.
(My opinions on SB are pretty well recorded though, so I'm not going
to go into that.)
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden