1
votes

I am trying to automate the creation of a smart mailbox in Apple Mail using criteria based on the currently selected message (e.g. create a folder to display all messages from the person who sent the current message). Clearly, I can go in and create a smart mailbox by hand, but because I do this regularly I am hoping to automate it.

I could not find any reference to Smart Mailboxes in the Dictionary for Mail. I did an internet search and could not find any sample code for manipulating Smart Mailboxes in Applescript, only a reference in a discussion from 2006 that says (bottom of the thread) that it can't be done: http://forums.macosxhints.com/archive/index.php/t-51935.html

I also found a script to bring up the create smart mailbox dialog, but that's not what I'm looking for.

Anyone know if there's a way to create/edit a smart mailbox in AppleScript?

Thanks.

1

1 Answers

1
votes

You have to use GUI scripting. I do most of my scripting using Python + appscript but here's a quick Applescript fragment to create a Smart Mailbox. I should note that not having formal Applescript support for handling smart mailbox is ludicrous.

tell application "Mail"
    activate
end tell

tell application "System Events" tell process "Mail" tell menu bar 1 tell menu bar item "Mailbox" tell menu "Mailbox" click menu item "New Smart Mailbox…" end tell end tell end tell

delay 1 keystroke "t" using shift down keystroke "e" keystroke "s" keystroke "t" keystroke tab keystroke "m" keystroke "o" keystroke "r" keystroke "e" end tell

end tell