 |
 |
Applescript & Cocoa: Mail a pdf attachment
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
OK, I almost have this figured out. I want my application to send an email using Applescript that has a pdf file as an attachment. I am providing the attachment path as a static path.
I always get an NSCannontCreateScriptCommandError (or something like that) for the
make new attachment... line of code. I don't know much about Applescript, so maybe this will be easy for someone?
The Applescript CODE from Script Editor:
tell application "Mail"
(* SPECIFY GENERAL CONTENT OF MESSAGE *)
set bodyvar to return & return & "Test body."
--set addrVar to "bogus@apple.com"
set addrNameVar to "Guinea Pig"
set myrecipient to "bogus@nowhere.com"
set theAttachment to "~/Documents/Test.pdf"
set subjectvar to "Email with Attachment!"
set mymail to (make new outgoing message at the beginning of outgoing messages with properties {subject:subjectvar, content:bodyvar})
tell mymail to make new to recipient at beginning of to recipients with properties {name:addrNameVar, address:myrecipient}
tell content
make new attachment with properties {file name:theAttachment} at before the first word of paragraph 0
end tell
set visible of mymail to true
end tell
Test.pdf is a real file in my Documents folder.
Thanks in advance!
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Just a guess (not having tried to use your code), but I would think that AppleScript would be unable to interpret the "~" in your file path. Certainly in ObjectiveC you have to expand the tilde to the full file path before using it (using [string expandTildeInPath] or something similar).
Try it with the fully qualified path name. The tilde character is usually used for the shell which then expands it, and in more recent times other programs have taken it on, but I doubt AppleScript would know what to do with it.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Thanks for the suggestion, but I still get the same error.
Any other suggestions folks?
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Two things:
1 - The user may not want to use mail.app
2 - Sometimes (in fact often) Cocoa apps do not support the "Make new x with y, z" syntax.
you may need to do:
make new X
make new Y at front of X
or
make new X
set properties of X to {foo: Z}
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
The original example code I posted above wouldn't even work in Script Editor. I am trying to first get it to work there, and then I will worry about getting to work in my Cocoa application.
Can anyone get the script above to work. I tried Diggory's suggestions, but still no luck.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Have a look at:
/Library/Scripts/Mail\ Scripts/Create New\ Message.scpt
for an example of how to attach to new messages
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Thanks Diggory, I figured it out be looking at that script!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|