I have certain emails that come in from various sources, and I need to file them away for future reference. Yes, I can drag and drop it into the folder, but I would like to create a keyboard shortcut to do this more easily.

This is my first attempt at Apple Scripts/Script editor. Here is the code I pieced together from several google searches to move the selected email. The end result is error "" number -1721.

Running MacBook Pro (13 inch, M1) MacOS: Monterey 12.6 Mail: 16.0 Script Editor: 2.11 (227) AppleScript 2.8

Any suggestions and ideas are welcome.

Thanks in advance!

on run {input, parameters}
    set target_account to "Gmail"
    set target_mailbox to "Inbox/Jobs"
    tell application "Mail"
        set theSelectedMessage to selection
        tell application "Mail"
            move the theMessage to mailbox target_mailbox of account target_account
        end tell
    end tell
    return input
end run
  • 1
    Mail has rules already in Preferences | Rules. Are you sure that won't do what you want? Sep 27, 2022 at 16:58
  • Yes. Those are based on specific criteria to filter messages into folders. There is no option for action on the selected message and move to a folder. You first have to create criteria for it such as to, from, in my contacts, not in my contact, junk, encrypted, or every message. In my case, it will be coming from various email sources, all to me, but all of my emails come to me.
    – Kyddrivers
    Sep 27, 2022 at 20:55
  • You've used a variable theMessage in your move command, but theMessage is not declared beforehand. You probably meant to use theSelectedMessage.
    – CJK
    Sep 28, 2022 at 2:31


You must log in to answer this question.

Browse other questions tagged .