Emily-
theAttachment variable represents an alias and the file class needs a specifier that is a file path.
Try defining the properties of theNewMassage as {file name:theAttachment}. Name coerces the alias (theAttachment) into a text object that is the path to the document and a valid specifier for the file class.
Applescript Language Guide in Apple's Developer Docs is a primary resource.
Craig
On Oct 18, 2011, at 7:54 PM, Emily Ong wrote: Here's a shortened version of the script:
tell application "Mail" set theSelection to selection set theMessage to item 1 of theSelection set theAttachment to choose file with prompt "Attach your file:"
try set theNewMessage to reply theMessage with opening window and reply to all tell theNewMessage make new text at before the first paragraph of content with data "message content or whatever" make new attachment at theNewMessage with properties {file:theAttachment}
make new attachment at theNewMessage with properties {file:theAttachment}
end tell end try end tell
and the console log… make new attachment at outgoing message id 95 with properties {file:alias "Macintosh HD:Users:ems:Desktop:10_4_FSA2.pdf"} --> error number -10024 end tell
On Oct 18, 2011, at 5:39 PM, Craig Sutherland wrote: The context of the statement is key. In the line of code make new attachment with properties {file name:theAttachment} at after last paragraph the make
is within a tell content block. Also, earlier in that example mail script, theAttachment is declared as a local variable that refers to a file alias returned by the choose file command. When your script executes that line of code, how is theAttachment defined?
Applescript's quirks are plentiful but eventually the object model becomes more predictable. Mail is one of the most puzzling apps to script in my experience, but the sample scripts Apple provides have code demonstrating most of the app's dictionary.
Craig Sutherland On Oct 18, 2011, at 4:28 PM, Emily Ong wrote: In the same sense, does that mean -
make new attachment with properties {file name:theAttachment} at after last paragraph
will not work when using a reply to a message? I just get a line of text with the attachment instead of the attachment itself. Seems like the rules are different when replying to an email.
Thanks, emily
On Oct 18, 2011, at 1:07 PM, Craig Sutherland wrote: Paul,
A message's content is read only. Take a look at the Text Suite for Mail to see the classes and elements available in it. It takes a lot of poking around in dictionaries to get a sense of the the inherited capabilities of different properties and elements. Lots.
Craig Sutherland On Oct 18, 2011, at 2:07 PM, Paul Scott wrote: Nice. Once again AS lives up to its promise of being user friendly!
Any idea why set content of theNewMessage to "###enter message content here###" doesn't work? And what's more, how could one possibly glean the correct solution from the dictionary?
Paul On Oct 18, 2011, at 11:50 AM, Zack Jarrett wrote: I use the following with reliable results: tell newMessage make new rich text at before the first paragraph of content with data "message content or whatever" end tell
Good luck! Zack
On Oct 18, 2011, at 10:08 AM, Emily Ong wrote: Hi there-
I'm trying to automate a simple reply all to a selected email from the inbox, but for some reason, I can't add content to the reply email. The console seems to say that the content is being "set", but nothing appears in the generated email (just the old reply to content). Am I doing something wrong here?
Thanks in advance!
tell application "Mail" set theSelection to selection set theMessage to item 1 of theSelection
try set theNewMessage to reply theMessage with opening window and reply to all tell theNewMessage set content of theNewMessage to "###enter message content here###" end tell
end try end tell
Emily Ong
Interactive Producer | Apple Inc.
Emily Ong
Interactive Producer | Apple Inc.
|