How to debug an AppleScript intended to be run by a Mail rule? I found a template in the Script Editor for a script intended to be run by Mail as the result of matching a rule (File -> New From Template -> Mail -> Mail Rule Action) and it starts out with:

using terms from application "Mail"
    on perform mail action with messages these_messages for rule this_rule


My question is how can I (for example) pick a message and then cause this script to execute as that message being part of these_messages so I can debug it?  I'm new to AppleScript and so I mostly want to poke around, display intermediate results, and slowly build up the script.
I created a mailbox on the same imap server and moved some junk mail into it (5 or 6 messages).  I then created my rule that called the script.  I disabled the other rules just to make sure that they were not doing anything weird.

Then select one or more messages in the sample mailbox and do Mail =&gt; Message =&gt; Apply Rules which will send the selected messages through the rules which ends up calling the script.  This is tied to CMD-OPT-L so its possible to cycle from compile and save in the script editor, switch to Mail to run the rules and back to the Script Editor all from the keyboard.