Applescript not working with mail rule

Discussion in 'Mac Programming' started by bergmef, Sep 23, 2009.

  1. bergmef macrumors 6502a

    Joined:
    Sep 20, 2005
    Location:
    Southeast of Baltimore, USA
    #1
    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
     
  2. electroshock macrumors 6502a

    electroshock

    Joined:
    Sep 7, 2009
    #2
    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?
     
  3. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #3
    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
     

Share This Page