I’ve looked around MacScripter and Googled but have had no luck trying to find a code snip to be able to drag and drop a file attachment onto a Applescript droplet to open a new email with that attachment.
I’ve found commands that open a new email and prompt for the file attachment,
set theAttachment to (choose file without invisibles)
and snips that allow hardcoding the path to the attachment,
set theAttachment to (((path to desktop) as string) & "myFile.jpg) as alias
But I’d really like the drag and drop functionality for a weekly email of a file. And I realize I need to use “on open what.”
How would I integrate drag and drop attachment functionality into this existing script? Thanks.
property mysubject : "Subject"
property Mysender : "Sender email"
property Myrecipient : "Recipient Email"
property EmailBody : "body message"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:mysubject, sender:Mysender, visible:true, content:EmailBody}
tell newMessage
make new to recipient with properties {address:Myrecipient}
end tell
end tell
try this, I used the script to send multiple files to multiple recipients
property nameList : {"name1", "name2"}
property emailList : {"name1@address.com", "name2@address.com"}
property myaccount : "John Doe <john@doe.com>"
property theSubject : "subject"
on run
tell application "Finder"
set sel to (get selection)
end tell
new_mail(sel)
end run
on open droppedFiles
new_mail(droppedFiles)
end open
on new_mail(theFiles)
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theSubject}
tell newMessage
set sender to myaccount
repeat with i from 1 to count nameList
make new to recipient at end of to recipients with properties {name:item i of nameList, address:item i of emailList}
end repeat
tell content
repeat with oneFile in theFiles
make new attachment with properties {file name:oneFile as alias} at after the last paragraph
end repeat
end tell
end tell
activate
end tell
end new_mail
Thanks, that worked great. I did some modifications and though I don’t need the multiple attachment function, I kept it in my version for the future. - Mark
It would probably be just one file. It seems my clients are always “misplacing/deleting/too lazy to look” for proofs I have sent them in the past.
I am considering making my worst offender a script will:
zip a pdf
attach to an email with her address
put the name of the file in the subject line
write “here you go” in the body
and send
After a bit of searching I stumbled upon this thread which is relevant to what i’m trying to achieve. I’m trying to construct a droplet that renames a pdf file, and then attaches the file to a new email. This is what i’ve been using so far:
on open the_droplet
set the_filename to "New File Name"
set the_subject to "Subject Line"
set email_list to {}
tell application "Contacts"
try
set the_persons to person "Someone"
on error
display dialog "Couldn't find contact"
end try
repeat with a_person in the_persons
set end of email_list to the value of a_person's email
end repeat
end tell
tell application "Finder"
set the_file to the selection as alias
repeat
set on_sale to text returned of (display dialog "What's the ON SALE Date?" default answer "" with title "Magazine Supply")
if on_sale > "" then exit repeat
end repeat
set the clipboard to on_sale
set name of the_file to the_filename & "." & name extension of the_file
set the_content to "Hello,
Copy attached for the publication as specified in the subject field of this email, with the on sale date of " & on_sale & "."
tell application "Mail"
activate
set new_message to make new outgoing message with properties {subject:the_subject, content:the_content & return & return, visible:true}
tell content of new_message
make new attachment with properties {file name:the_file} at after the last word of the last paragraph
end tell
tell new_message
repeat with an_item in email_list
repeat with an_address_item in an_item
make new to recipient at end of to recipients with properties {address:an_address_item}
end repeat
end repeat
end tell
delay 2
set the_signature to "A Signature"
set message signature of new_message to signature the_signature
end tell
end tell
end open
It does work ‘ok’, although it’s not very stable. After dropping the file onto the droplet it does everything apart from attaching the file to the email. But when I repeat the same process a second time, it works correctly (including attaching the file). Before I plough ahead and produce literally hundreds of these scripts, I’m intrigued to know why it only works the second time around.
I’ve tried the above script from StafanK which works very well. I would like to either adapt the script to incorporate some of the other elements I need (I haven’t used handlers before), or tweak the script i’ve currently got.
I’m using Yosemite on a shared network NAS drive.
Anyone’s help would be much appreciated.
I’ve noticed the droplet becomes unstable when it is copied and pasted into a new folder. The idea is to have several ‘master’ scripts which are then duplicated to specific job folders.