Jump to content
Sign in to follow this  
jhncbrwn

Trying to attach multiple files from file buffer to email, help requested

Recommended Posts

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.

 

Share this post


Link to post

 

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

Share this post


Link to post

Hi David,

 

Thanks for your help.

 

It took me another couple of hours but I got it to work! :D

 

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

Share this post


Link to post

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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  
×
×
  • Create New...