Scripting Attachments in Mail

Hi All,

I’m new to Applescript and I’m trying to create a script that allows a user to enter a file path and then attach that file to a new mail document. I’m having problems with the file path section as Mail doesn’t seem to accept the file path text.

set theName to "SomeOne"
set theAddress to "someone@somewhere.com"
set theSubject to "Mail Subject"
set theBody to "Body Text"
set theAttachment to "OSX HD:User:evan:Desktop:document.pdf"
tell application "Mail"
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		tell content
			make new attachment with properties {file name:theAttachment} at after the last paragraph
		end tell
	end tell
	activate
end tell

Any help would be great.

If you change this:

set theAttachment to “OSX HD:User:evan:Desktop:document.pdf”

To this:

set theAttachment to “OSX HD:User:evan:Desktop:document.pdf” as alias

Does it work?

Thanks Rob.

That did the trick…

The final script looks like this.

set theName to "SomeOne"
set theAddress to "someone@somewhere.com"
set theSubject to "Mail Subject"
set theBody to "Body Text"
set theAttachment to "OSX HD:Users:evan:Desktop:document.pdf" as alias
tell application "Mail"
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		tell content
			make new attachment with properties {file name:theAttachment} at after the last paragraph
		end tell
	end tell
	activate
end tell

Thanks again.

Evan