Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator Folder Actions - Use filename as subject in email

I regularly email .pdf atttachments to my head office. These are hand-written sales orders which are scanned in. The scanner software gives each file a sequential filename (eg. OrderNo_110612).


I have set up a Folder Action in Automator to create a new email and send the file as an attachment when it is added to the folder.


Get Selected Finder Items

New Mail Message

Send Outgoing Messages


I would really like to add the filename to the subject of the email. Is there a script I can run within the 'Run Shell Script' action that will extract the filename and can then be used as a variable in the subject field? This would allow both myself and head office to easily find the email at a later date should the need arise.


Any help would be gratefully received. I am not a programmer, although I understand the principle of variables etc..


I am using OS X Lion 10.7.2


Any help would be really gratefully received.


Many thanks

iMac, Mac OS X (10.7.2)

Posted on Nov 15, 2011 11:17 AM

Reply
Question marked as Best reply

Posted on Nov 15, 2011 1:07 PM

to do this you want to use a variable. It's a little tricky, but not too bad. basically do the following. First set up a couple of variables (call them filePath and fileName). then add these actions:


  1. get selected finder items - this passes a list of file references.
  2. set value of variable - filePath - this saves the file references in a variable, and passes them on
  3. run applescript - use the applescript below to get the file name and pass it on
  4. set value of variable - fileName - this saves the file name in a second variable
  5. get value of variable - filePath - recover the file reference variable and pass it on. make sure this action does not receive input
  6. new mail message - makes a new mail message with the appropriate attachment. add the fileName variable to the subject line by dragging it from the variable list.
19 replies
Question marked as Best reply

Nov 15, 2011 1:07 PM in response to chomper123

to do this you want to use a variable. It's a little tricky, but not too bad. basically do the following. First set up a couple of variables (call them filePath and fileName). then add these actions:


  1. get selected finder items - this passes a list of file references.
  2. set value of variable - filePath - this saves the file references in a variable, and passes them on
  3. run applescript - use the applescript below to get the file name and pass it on
  4. set value of variable - fileName - this saves the file name in a second variable
  5. get value of variable - filePath - recover the file reference variable and pass it on. make sure this action does not receive input
  6. new mail message - makes a new mail message with the appropriate attachment. add the fileName variable to the subject line by dragging it from the variable list.

Nov 15, 2011 1:41 PM in response to twtwtw

OK, I've done what you have said and I feel like I'm very close to getting there. As it stands, the script appears to be working and my new mail message has the filename as the subject which is great. I'm struggling to get the file attached to the email now.


Do I need to add anything between step 5 & 6 in your answer. Right now it's adding the file path to the body of the email. Do I have to add another Get Selected Finder Items action in before the New Mail Message? or something like that?


Thanks.


ps. I will only ever send one file at a time so the script works fine. Is it possible to remove the extension from the fileName variable. Not essential and I don't want to waste your time. Just a luxury.

Nov 15, 2011 5:58 PM in response to chomper123

The New Mail Message action will attach files that are passed to it, or append text that is passed to it - my guess is that you are missing the option to ignore the input when getting the variable, so the file name you got (text) is what is being handled. I also have a Get Names of Finder Items action on myAutomator homepage that will get just the name part (it also works with multiple files).

Oct 16, 2013 9:16 PM in response to chomper123

Does anyone have a Automator workflow they are willing to share that performs the following tasks


Here are the steps:

  1. Detect new file has been added to folder
  2. Create new outlook email and set subject line to the name of the attachment Or append with date
  3. Attach file to email
  4. Send Email
  5. Move file to sent folder


I need this action because: I have a report I need to export and email as an attachment every day. I would like to be able to save the report to a folder and have it automatically sent as an attachment and then move the file to a sent folder.


Any help would be much appreciated. I cannot get the subject line part to work

Automator Folder Actions - Use filename as subject in email

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.