(* File email by sender -- Original script created by Mark L. Chang: http://www.acmelab.org/geeklog/article.php?story=20040415053340592 Modifications by Paul Schilling Modified to support: - Optional prompt - Optional subfolder - Optional set mailbox to name from Address Book - Multiple email messages selected - Support multiple accounts, saves to mailbox on that IMAP account for example - Automatically create the new mailbox if not prompting user - Hard coded email aliases (replaced with Address Book lookup) Installation: 1) Open Applications -> AppleScript -> Script Editor 2) Copy the code. 3) Edit options at the top of the file 4) Save to ~/Library/Scripts/Mail Scripts/File email by sender___ctl-s.scpt When messages are selected pressing ^s will save the messages *) (*** *** Options ***) property checkAddressBook : 1 property promptUser : 0 property subFolder : "" (* EX: set emailAliases to {{"foo@bar.com", "foo"}, {"foobar@bar.com", "foo"}} *) set emailAliases to {} tell application "Mail" set theSelectedMessage to selection if (count of theSelectedMessage) is equal to 0 then display dialog "Please select a message in Mail first, then run this script again." else repeat with theMsg in theSelectedMessage set thisMessage to item 1 of theMsg set theFrom to extract address from sender of thisMessage set theAccount to account of mailbox of thisMessage set theAccountName to name of theAccount set theMailbox to "" (* Look for the email address in the Address Book *) if checkAddressBook is equal to 1 then tell application "Address Book" repeat with thePerson in people repeat with theirEmail in emails of thePerson set theirEmailAddress to (value of theirEmail) as string if theirEmailAddress is theFrom then set theMailbox to name of thePerson exit repeat end if end repeat end repeat end tell end if (* Look for an alias *) if theMailbox is "" then repeat with L1 in emailAliases set aliasFrom to item 1 of L1 if theFrom is aliasFrom then set theMailbox to item 2 of L1 end if end repeat end if (* Get mailbox from the message *) if theMailbox is "" then set astid to AppleScript's text item delimiters set AppleScript's text item delimiters to "@" set theEmailPart to item 1 of (every text item of theFrom) set AppleScript's text item delimiters to astid set theMailbox to theEmailPart end if (* Prepend the subFolder to theMailbox if it is defined *) if subFolder is not "" then set theMailbox to subFolder & "/" & theMailbox end if (* Not prompting the user so make the mailbox if it does not exist *) if promptUser is equal to 0 then try set mboxName to mailbox named theMailbox of account theAccountName on error try tell theAccount to make new mailbox with properties {name:theMailbox} on error display dialog "Error creating the mailbox: " & theMailbox end try end try end if if the mailbox theMailbox of account theAccountName exists then if promptUser is equal to 1 then display dialog "Saving to: " & theAccountName & " | " & theMailbox if button returned of result = "OK" then tell application "Mail" move the theMsg to mailbox theMailbox of account theAccountName end tell end if else tell application "Mail" move the theMsg to mailbox theMailbox of account theAccountName end tell end if else display dialog theMailbox & " does not exist on " & theAccountName & ". Choose a new mailbox." default answer "" set theNewMailbox to (text returned of result) as string set theMailbox to theNewMailbox if the mailbox theMailbox of account theAccountName exists then tell application "Mail" move the theMsg to mailbox theMailbox of account theAccountName end tell else display dialog "Mailbox " & theMailbox & " does not exist." buttons "Cancel" end if end if end repeat end if end tell