jhncbrwn Posted May 12, 2013 Share Posted May 12, 2013 I'm trying to make a workflow runs as a file action. It should take multiple files from the file buffer and attach them to an email, to be send to a predetermined address. I would really appreciate it if somebody could help me with the attachment part. This is what I have: set MyAttachments to the "{query}" tell application "Mail" activate set MyMessage to make new outgoing message with properties {subject:"Subject line goes here", content:"Body goes here", visible:true} tell MyMessage make new to recipient with properties {address:"Addres_goes_here@gmail.com"} repeat with EachAttachment in MyAttachments make new attachment with properties {file name:(EachAttachment as alias)} at after last paragraph of content end repeat save end tell end tell Thanks in advance for your help. Link to comment
jdfwarrior Posted May 13, 2013 Share Posted May 13, 2013 I'm trying to make a workflow runs as a file action. It should take multiple files from the file buffer and attach them to an email, to be send to a predetermined address. I would really appreciate it if somebody could help me with the attachment part. This is what I have: set MyAttachments to the "{query}" tell application "Mail" activate set MyMessage to make new outgoing message with properties {subject:"Subject line goes here", content:"Body goes here", visible:true} tell MyMessage make new to recipient with properties {address:"Addres_goes_here@gmail.com"} repeat with EachAttachment in MyAttachments make new attachment with properties {file name:(EachAttachment as alias)} at after last paragraph of content end repeat save end tell end tell Thanks in advance for your help. Results are passed as a tab delimited string, not as a multi item object. You would need to use AppleScript to split the string into multiple items in order to iterate oer them Link to comment
jhncbrwn Posted May 13, 2013 Author Share Posted May 13, 2013 Hi David, Thanks for your help. It took me another couple of hours but I got it to work! I posted the code below for anybody to use. set filelist to "{query}" set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to "\t" set theArray to every text item of filelist set AppleScript's text item delimiters to oldDelimiters tell application "Mail" activate tell (make new outgoing message at end of outgoing messages with properties {visible:true, subject:"Subject goes here", content:"Body goes here"}) make new to recipient at end of to recipients with properties {address:"Addres_goes_here@gmail.com"} repeat with eachitem in theArray set t to POSIX file eachitem make new attachment with properties {file name:t as alias} at after last paragraph end repeat end tell end tell Link to comment
uscmeche Posted October 10, 2013 Share Posted October 10, 2013 Was browsing and really appreciate the script. Added a bit to it for enumerating the files listed. Hopefully this code works for others. set filelist to "{query}" set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set theArray to every text item of filelist set AppleScript's text item delimiters to oldDelimiters set itemList to "Attachments" & return set theCount to 0 if length of theArray is greater than 1 then repeat with eachitem in theArray set theCount to theCount + 1 try set oldDelims to AppleScript's text item delimiters -- save their current state set AppleScript's text item delimiters to {"/"} -- declare new delimiters set itemList to itemList & theCount & ". " & the last text item of eachitem & return set AppleScript's text item delimiters to oldDelims -- restore them on error set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong end try end repeat else set eachitem to item 1 of theArray set theCount to theCount + 1 try set oldDelims to AppleScript's text item delimiters -- save their current state set AppleScript's text item delimiters to {"/"} -- declare new delimiters set itemList to itemList & theCount & ". " & the last text item of eachitem set AppleScript's text item delimiters to oldDelims -- restore them on error set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong end try end if tell application "Mail" activate tell (make new outgoing message at end of outgoing messages with properties {visible:true, subject:"- - ATTACHMENT(S) ENCLOSED ", content:itemList & return}) repeat with eachitem in theArray set t to POSIX file eachitem make new attachment with properties {file name:t as alias} at after last paragraph end repeat end tell end tell Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now