Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AppleScript to move selected Mail messages to a particular mailbox of a particular account. User is asked only once. [This script]( let's you choose an account first.
Mail Filer
Files messages in using type ahead. Displays one dialog containing all mailboxes and accounts.
Created by Andreas Zeitler on 2013-09-13
Copyright Mac OS X Screencasts 2013. All rights reserved.
set myMailboxes to {}
tell application "Mail"
-- assemble a list of all mailboxes of all accounts
set allAccounts to (name of every account) as list
repeat with thisAccount in allAccounts
set theseMailboxes to (name of every mailbox of account thisAccount) as list
repeat with thisMailbox in theseMailboxes
set the end of myMailboxes to (thisMailbox as string) & "\t\t\t" & (thisAccount as string)
end repeat
end repeat
-- present list
choose from list myMailboxes with title "Choose Mailbox…" with prompt "Please select one account" without multiple selections allowed
set chosenMailbox to result as string
-- split mailbox and account from result
set oldDelimits to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\t\t\t"
set mailboxAndAccount to every text item of chosenMailbox
set AppleScript's text item delimiters to oldDelimits
-- these are the mailbox and account we need to move messages to
set chosenMailbox to first item of mailboxAndAccount
set chosenAccount to second item of mailboxAndAccount
-- move selected messages to chosen mailbox of chosen account
set s to selection
if s is not "" then
repeat with currentMessage in s
move currentMessage to (first mailbox whose name is chosenMailbox) of account chosenAccount
end repeat
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment