Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bergmef

macrumors 6502a
Original poster
Sep 20, 2005
797
87
North East, MD, USA
First and foremost, I don't program. All I want is an applescript that automatically downloads attachments from my work email. The first part is easy with a mail rule. The script is giving me a problem. I found one that a guy was using to download torrent files and others said it worked. I altered the location for my hard drive but damn if I can get it to work. I cut and pasted it into the applescript editor and saved it, added it to the rule and voila ... didn't work. Here it is, any suggestions?!?

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with oneMessage in theMessages
set {mail attachment:theAttachments} to oneMessage
repeat with oneAttachment in mail attachments of oneMessage
save oneAttachment in ("Macintosh HD:Users:bergmef:Desktop:") & (name of oneAttachment)
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
 

electroshock

macrumors 6502a
Sep 7, 2009
641
0
I'm not an AppleScript whiz but might be that you're not defining the rule 'theRule' anywhere in the code snippet that you posted.

As a result, I don't think it's matching any action criteria to kick in and do its thing... maybe?
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
I'm not quite sure about the mail rule, what it contains, why it's necessary ... maybe with more information we can come up with something closer to what you're expecting.

This, however, should be a stop gap:

Code:
set theFolder to ((choose folder with prompt "Select folder where you want to save your mail attachments") as string)

tell application "Mail"
	set frontViewer to message viewer 1
	set theMsgs to messages of frontViewer
	repeat with msg in theMsgs
		if the mail attachment of msg ≠ {} then
			repeat with n from 1 to (count of mail attachments of msg)
				set theName to name of (mail attachment n of msg)
				set fullPath to theFolder & theName
				save (mail attachment n of msg) in file fullPath
			end repeat
		end if
	end repeat
	
end tell

This will save off all the attachments in your Inbox to the folder you specify. If the rule is moving off the work emails to another mailbox, we should be able to handle that, no problem.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.