When I send a work email with attachments to my home computer I want the home computer to automatically get the attachments once the mail has arrived and put them in one of my iCloud folders. Is there a way to do this? I have Hazel. And my OS is High Sierra. Something like "When an email arrives with subject line “SKUUPC” take attachments from the email and move them to “Inventory” folder on my iCloud.
Have you looked at IFTTT or Zapier? This seems like it is clearly in their wheelhouse.
I tried Zapier. For some reason they zip up the file when they move it. And when I unzip the file it puts it into another folder. I would prefer to just have the actual files that are the attachments. I’ll give IFTT a try. Thank you.
Yes. IFTTT worked way better. The attachment went straight into my Dropbox folder and no zip files. Now I’ll get Hazel to send the file from Dropbox to the Shortcuts folder and the fun begins. Thanks again capcrime.
Plus IFTTT works way faster. Zapier has a 15 minute delay unless you are on a higher pay tier.
Another approach is to use AppleScript. With help from the wizards on MacScripter, I just updated a script I’ve been using for years with Mail.app to get it to run on Catalina. Instructions for using a script as a mail rule are here. The actual script I run is this:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set attachmentsFolder to ((path to downloads folder) as Unicode text) & "Attachments"
tell application "Mail"
repeat with eachMessage in theMessages
--set the sub folder for the attachments to the senders mail address.
-- All future attachments from this sender will the be put here.
set subFolder to (sender of eachMessage)
-- set up the folder name for this mail message's attachments. We use the time stamp of the date received time stamp
set {year:y, month:m, day:d, hours:h, minutes:min} to eachMessage's date received
set timeStamp to (y & "-" & my pad(m as integer) & "-" & my pad(d) & "_" & my pad(h) & "-" & my pad(min)) as Unicode text -- month as number
set attachCount to count of (mail attachments of eachMessage)
if attachCount is not equal to 0 then
display notification ¬
"Mail is saving attachments!" with title ¬
"Saving Attachments" subtitle "Note any system unresponsiveness"
-- use the unix /bin/test command to test if the timeStamp folder exists. if not then create it and any intermediate directories as required
if (do shell script "/bin/test -e " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder & "/" & timeStamp) & " ; echo $?") is "1" then
-- 1 is false
do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder & "/" & timeStamp)
end if
try
-- Save the attachment
tell eachMessage
repeat with theAttachment in (mail attachments)
set originalName to name of theAttachment
set savePath to (attachmentsFolder & ":" & subFolder & ":" & timeStamp & ":" & originalName) as «class furl»
try
with timeout of 1800 seconds
save theAttachment in savePath
end timeout
end try
end repeat
end tell
on error msg
display notification msg
end try
end if
end repeat
end tell
end perform mail action with messages
end using terms from
on pad(n)
return text -2 thru -1 of ("0" & n)
end pad
That’s a good script thanks. I am now using Zapier again. I use their email address to Dropbox. Then I have Hazel watch that Dropbox folder and when a file lands in it Hazel unzips the fill grabs the two files inside the new folder and sends them to my iCloud folder. Then deletes the empty zipped folder. I also put an AppleScript that uses a Pushcut web hook in Hazel to notify me when the files have been moved. But I’m having trouble with it as the Pushcut notification works sometimes and then sometimes not. But Zapier and Hazel work every time. I think it has something to do with my computer screen locking.
Hi everyone, may I ask if this script still works for anyone, if running macOS 10.15.7? Whatever I try, the script will not take any action if I try to trigger it by action. The action itself works, e.g. setting a flag if matched.