I have a little problem. Maybe you can help me with it.
I am shooting many portraits for a client. Like 200 each day.
I have to email every single Portrait via Mail. A gallery with all portraits in one is not allowed because of privacy stuff.
The client wants definitely emails.
I tried to program an Applescript/Automator action to do this automatically.
My plan is to name all the files like so: name@client.com_2847.jpg and let the action do the rest of the magic.
It kind of works, except that i am not able to extract the mail address from the jpg file.
How do I extract the Email from the file (for example deleting the last 9 digits) and putting it in as the recipient?
I saw a similar question here: Automator -> send file to email (from filename)
but for some reason I get many syntax errors.
thanks!
Best Answer
Since in your question, you did not include any code, error message(s), or even how you were implementing your solution, I'll offer the following as an example of how I might automate the task at hand. Note that while I looked at the link in your question, nonetheless, since it was for Outlook and you've tagged the question with mail.app, I'm going to ignore what was linked and proceed my way from scratch.
In this example scenario, I created a hierarchical folder structure under ~/Photos, e.g. ~/Photos/Clients/Name/Emailed Photos, and this is the folder that I'll drag the target photos to, that have the naming convention e.g. name@client.com_2847.jpg, and the folder to which the Automator Folder Action workflow will be attached to.
In Automator:
~/Library/Workflows/Applications/Folder Actions/Email Photos to name@client.workflow
Now when you drag photos having the naming convention, e.g. name@client.com_2847.jpg to the target folder, e.g. ~/Photos/Clients/Name/Emailed Photos, one email for each photo will be created and the target file attached. Initially the email will not be automatically sent until you uncomment, remove the
--
from in front of the-- send theMessage
line of code, and save the changes. This is initially commented out so you can test with one file and get your subject and message setup to meet your needs. I'd use a file that has your email address in it for testing purposes, doing one at first then several at one time.The email message subject and content are initially set to "Portraits" and Photo attached." respectively, as placeholders. Additionally there is another line of commented code,
-- delay 2
, above the-- send theMessage
line of code that you may need/want to implement if adding a large number of files at the same time to the target folder which has the Folder Action attached, as rapid sending may cause issues. Note that the value of thedelay
command may need to be adjusted higher as appropriate to accommodate the conditions and you'll just have to do some testing to see what works for you. While I did do some testing, I used a very small file (3 KB) that I replicated and sequentially named for testing purposes. I'll assume your photos will be much larger in size.AppleScript code:
Note that as coded, if a file dropped into the target folder, the folder to which the Folder Action is attached, does not conform to the naming convention of e.g. name@client.com_2847.jpg, then no email for that file should be created, unless the portion of the filename preceding the underscore contains the @ symbol and any other characters. In other words, the only error checking the code, as is, attempts to validate is the filename contains a valid email address only on the premise if it has both an underscore and @ symbol, then it assumes the filename conforms to e.g. name@client.com_2847.jpg. More strict error checking could be coded, however I'll leave that to you if what's presented isn't adequate.
Additionally, other forms of general error checking could be implemented, i.e. making sure the file was actually attached before sending, etc., however this answer is meant to be a simple example, not necessarily a fully coded solution. The onus is on you to insure you implement appropriate error checking as conditions warrant.
As you might be able to tell by the images below, I wrote and tested this in a pre OS X 10.9 environment, OS X 10.8.6 to be specific and I have "Enable access for assistive devices" checked in Accessibility preferences. In OS X 10.9 and later, including the latest version of macOS, Sierra, you may need to add Mail and or Automator to System Preferences > Security & Privacy > Privacy > Accessibility in order for the Folder Action to work. I'm not in a position to test in those versions at the moment, however if it doesn't work for you, then add these apps accordingly.