AppleScript Programming/ archive selected inbox messages

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This script tell is supposed to tell to move the selected mails to a certain directory/mailbox. Is supposed to work with gmail, but is not general. It doesn't work unless everything is configured for this script.

(* This script is commented out because it needs work.
tell application "Mail"
	set selectedMails to the selection
	if the length of selectedMails is greater than 0 then
		repeat with theMessage in selectedMails
			if the name of the mailbox of theMessage is "INBOX" then
				-- Set "gmail" to whatever your account is called in's preferences
				if the account of the mailbox of theMessage is account "gmail" then
					-- Note: instead of "All Mail" below, I had to use "[Gmail]/All Mail" -Simon, using Mail 3.5 (930.3) & Gmail w/ IMAP
					move theMessage to mailbox "All Mail" in account "gmail"
				-- Add custom accounts with custom names and custom archive mailboxes here
				-- else if the account of the mailbox of theMessage is account "uni" then
				--	move theMessage to mailbox "Archive" in account "uni"
					say "Your mail didn't belong to any account I know."
				end if
				say "Only mails in inbox can be moved"
			end if
		end repeat
		say "You have to select mails first"
	end if
end tell

Next Page: QuickTime full screen | Previous Page: Mail alert

Home: AppleScript Programming