• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mail Scripting - Copy Messages to Finder Folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mail Scripting - Copy Messages to Finder Folder


  • Subject: Mail Scripting - Copy Messages to Finder Folder
  • From: Bruce Robertson <email@hidden>
  • Date: Wed, 26 Jun 2013 19:19:26 -0700

I was given the following script to troubleshoot.

It fails for items in On My Mac mailboxes but works OK for high level mailboxes.

The purpose is to copy selected messages to a user designated Finder folder.
So if you have suggestion for other methods to accomplish this result, of course they are welcome.

It appears that frailties of Mail scripting have been discussed at great length here - but now I need to solve this particular problem and my attempt to use my email archives has not led me to a solution.

Thanks for your suggestions.

I'm testing this on 10.7.5

Bruce Robertson



tell application "Mail"
	set msgs to selection

	if length of msgs is not 0 then
		display dialog "Export selected message(s)?"
		if the button returned of the result is "OK" then

			set theFolder to POSIX path of (choose folder with prompt "Save Exported Messages to..." without invisibles)

			repeat with msg in msgs

				-- determine date received of msg and put into YYYYMMDD format
				set msgDate to date received of msg
				-- parse date SEMversion below using proc pad2()
				set {year:y, month:m, day:d, hours:h, minutes:min} to (msgDate)
				set msgDate to ("" & y & my pad2(m as integer) & my pad2(d))

				-- assign subject of msg
				set msgSubject to (subject of msg)

				-- create filename.eml to be use as title saved
				set newFile to (msgDate & "_" & msgSubject & ".eml") as rich text
				set newFilePath to theFolder & newFile as rich text
				set newFilePath2 to theFolder & newFile & "x" as rich text


				-- copy mail message to the folder and prepend date-time to file name
				set messageId to id of msg
				set myFolder to POSIX path of (account directory of account of mailbox of msg as Unicode text)
				set cmd to "find " & quoted form of myFolder & " \\( -name \"" & messageId & ".eml\" -a -exec cp -a {} " & quoted form of newFilePath & " \\; \\) -o \\( -name \"" & messageId & ".emlx\" -a -exec cp -a {} " & quoted form of newFilePath2 & " \\; \\)"
				do shell script cmd

			end repeat

			beep 2
			display dialog "Done exporting " & length of msgs & " messages."
		end if -- OK to export msgs
	end if -- msgs > 0
end tell

on pad2(n)
	return text -2 thru -1 of ("00" & n)
end pad2


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: Mail Scripting - Copy Messages to Finder Folder
      • From: Axel Luttgens <email@hidden>
    • Re: Mail Scripting - Copy Messages to Finder Folder
      • From: Axel Luttgens <email@hidden>
  • Prev by Date: Re: unresponsive apps and applescript
  • Next by Date: Re: unresponsive apps and applescript
  • Previous by thread: Re: ScriptUI Problems Reported with InDesign CC - In AS Too ???
  • Next by thread: Re: Mail Scripting - Copy Messages to Finder Folder
  • Index(es):
    • Date
    • Thread