Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript and mail attachments

Hi All,
I am very new to applescript, and i am trying to create an email, and add an attachment to it.
Unfortunately, the file specified is not attached even though it exists. Could someone tell me kindly what i am doing wrong?

This is my (very basic) script :

set msg to "no"
tell application "Finder"
if exists file "Macintosh HD:Users:jonweston:Documents:Tree Safety:Accountant:Payment Record Running 31.pdf" then
set msg to "yes"
end if
end tell

display dialog msg


set theAttachment to "Macintosh HD:Users:jonweston:Documents:Tree Safety:Accountant:Payment Record Running 31.pdf"
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"My Subject", content:"My Body"}
tell content of theMessage
make new attachment with properties {file name:theAttachment} at after last paragraph
end tell
end tell

Thanks a lot
FP

Mac Pro, Mac OS X (10.6.5)

Posted on Jan 27, 2011 7:24 AM

Reply
1 reply

Jan 27, 2011 9:08 AM in response to pinkmoon123

You pretty much have it worked out, which is good going if you're new to AppleScript. There's one change necessary. Mail is expecting to be fed an alias, not a string. Try this change:

make new attachment with properties {file name:"Macintosh HD:Users:jonweston:Documents:Tree Safety:Accountant:Payment Record Running 31.pdf" as alias} at after last paragraph

Note the addition of "as alias" that follows your path. AppleScript is often deceptively flexible when it comes to types (alias, string, number etc), but in some cases it becomes very important. If you ever find file-related activities failing then check the type you're feeding in.

Applescript and mail attachments

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.