AppleScript to save emails as txt

Discussion in 'Mac Programming' started by Jagra, Feb 17, 2010.

  1. Jagra macrumors newbie

    Joined:
    Feb 17, 2010
    #1
    I have a rule in Mail, which moves specific emails to a specific email folder: "TestSpecs".

    Now I need an AppleScript to run in conjunction with the rule, which will save each email as a txt file in a folder on my desktop.

    I get this far (not very far I know) now it has me stuck.
    set theFolder to "/Users/Jagra/Desktop/TestSpecs" as string

    tell application "Mail"
    activate
    ????
    end tell

    Can anyone suggest how I go about this?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    This is pulled from a script I use. It's the basic outline to get you started:

    Code:
    on perform_mail_action(theData)
    	tell application "Mail"
    		set theSelectedMessages to |SelectedMessages| of theData
    		repeat with theMessage in theSelectedMessages
    			try
    				-- process theMessage
    			on error theError
    				display dialog "ERROR: " & theError
    			end try
    		end repeat
    	end tell
    end perform_mail_action
    That function gets called by Mail. Now you need to figure out how to get the email message as plain text and how to write that to a file. I suggest first start googling around as those are simple tasks. Also in AppleScript Editor, go to File > Open Dictionary and select Mail to see what you can do with a message.
     

Share This Page