Change Congress

« free flags II | Main | good news for free spectrum »

Mail.app Trivia: Where does AppleScript run best?

Last month, I posted a link to some free software for Mail.app OS X that Jonathan Nathan is offering under the GPL. This code was designed to allow a user of Mail.app to move a message to a folder with a single keystroke.

Since then, there's been some progress in the Mail.app app, but not as much as one would think. Apple has released Panther, and Aaron has released a script that does the same thing within Panther.

Both Jonathan's and Aaron's nicely move a message to a folder. Aaron's is built to enable the binding of a keystroke to an AppleScript directly. But both have a common weakness: After a message is moved, the system forgets which message it has last selected.

Weird, because, e.g., this very simple script within Microsoft's Entourage does the same thing, but without forgetting the last message selected:


--Open this script in a new Script Editor window.



tell application "Microsoft Entourage"

    set curMsgs to current messages

    repeat with theMsg in curMsgs

        move theMsg to folder " friends" in folder "Archive"

    end repeat

end tell


(Update:: this cool applescript formatting trick is thanks to another Jon Nathan script -- available here)

Note in Entourage, if you save the script with a "\cX" in the script name, then ctrl+X will run the script.

It is surprising, one might think, that Microsoft's mail app operates more robustly with AppleScript than Apple's. As well as a bit frustrating.

|

Comments (2)

I have to agree. I don't know why Apple can't make Applescript's hooks for a command like "move" behave the same way they do in the UI.

The script I'm using is a total hack that works around the problem. I use Applescript to copy the message and the UI to delete it from the folder. In Aaron's script, if you change the following line:

set mailbox of (item i of the_selection) to mailbox target_mailbox of account target_account

to

copy (item i of the_selection) to mailbox target_mailbox of account target_account

and press delete after you run the script, the next message is properly highlighted. To me, the extra keystroke isn't such a pain, especially since I often file a message to several different folders. It's also a lot faster than using the mouse!

Thanks for the really helpful tip. You can use subfolders with notation "folder/subfolder" in the first line of the script.

- JuHa