Jump to content

Add file to email reply

Recommended Posts

I am trying to get a workflow that would allow me to add a file to reply window I have open. 

The simplest thing would be if this was a file action. There are already file actions for starting a new mail window with the file as an attachment.


Anyone has any ideas how to insert the file into an open mail window? 

Link to comment

Yikes, um, wow... I think this can be done but this one would take a little Applescript.


Essentially what you would have to do is.. either setup a workflow that you would use with Mail.app sitting on the mail message that you want to reply to, do some Applescript that would find the reply window and then insert a file based on that. The first way would probably be the most preferred because in the second way, if you have multiple windows open, you have to rely on your code to pick the appropriate window. Creating works easily because its just telling it to "create a new message, add this file". There isn't a specific message associated with it or anything.


Assuming that the file could easily be added via Applescript, and I'm pretty sure it can (if you could do it when creating a message, why couldn't you attach to a new reply?), you would hit a workflow that would tell Mail.app to activate, grab the selected message, create a reply to that message, and attach the file. The only thing is though, you still don't have a file selected... Sorry, I'm thinking through this as I'm typing. 


Maybe you could try the other method but personally I'd think it would be a lot easier to just initiate the reply in Mail, bring up Alfred, find the file you want, and just drag / drop it on the new reply message.

Link to comment

Here's the applescript snippet that will get you most of the way there:


on alfred_script(theFilePath)
	set theFile to theFilePath as POSIX file
	tell application "Mail"
		-- get a list of all mail message windows
		set theMessageList to every outgoing message
		-- either select the front most mail window or create one if none exist
		if length of theMessageList is greater than 0 then
			set theMessage to item 1 of theMessageList
			set theMessage to make new outgoing message with properties {visible:true}
		end if
		-- add the file to the message
		tell content of theMessage
			make new attachment with properties {file name:theFile as alias} at after last paragraph
		end tell
	end tell
end alfred_script


I hooked this up after a file action and it will either append a file to an existing message or create a new message with the file if no messages exist. The applescript currently doesn't take multiple files, but you could modify it to do so by parsing the resulting tab-delimited string from the file action. One issue I can't figure out (and don't have time) is that when I run this within the applescript editor, it will correctly append a second or third attachment to an existing message. In Alfred, it seems to replace the existing attachment. Hope this gets you on your way, though.

Link to comment

Thanks for the suggestions after some googling I am almost there. I think you are right David attaching a file to the currently selected message seems to be more stable, still need to work out some kinks. 


Thanks mlgill that was a great starting point, since I have not used applescripts before (relatively new to osx), your suggestion helped a lot. 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...