Skip to content

My Incompatibility with AppleScript

Have a look at the following, which is the AppleScript code needed to move a selected message(s) in Apple Mail to another folder:

property target_mailbox : "@Waiting for..."
property target_account : "Work"

using terms from application "Mail"
    on perform mail action with messages the_selection
        if the_selection = {} then
        end if
        tell application "Mail"
            repeat with i from 1 to (count of the_selection)
                set mailbox of (item i of the_selection) to mailbox target_mailbox of account target_account
            end repeat
        end tell
    end perform mail action with messages
end using terms from

using terms from application "Mail"
    on run
        tell application "Mail" to set sel to selection
        tell me to perform mail action with messages (sel)
    end run
end using terms from

What is it with me and AppleScript? I can achieve just about anything I want in PHP, without having to refer much to examples. But in a million years I wouldn’t have been able to write the above from scratch.

Published inTechnology

One Comment

  1. Actually, this is far more complex than it needs to be.

    tell application “Mail”

       set selmsgs to selection

       repeat with eachmsg in selmsgs

          move eachmsg to mailbox “mailboxname”

       end repeat

    end tell

    You only need all of those “using terms from”, “property”, and “on” lines to handle special cases which don’t apply when you’re just triggering a script from the menu.

Agree? Disagree? What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.