applescriptapple-mail

How to get a simple applescript to run in apple mail?


I seem to be struggling just getting a simple script to run.

My script doesn't do much right now, just loops through emails and gets the senders email and name.

using terms from application "Mail"
    on perform mail action with messages these_messages for rule this_rule
        tell application "Mail"
            set the message_count to the count of these_messages
            repeat with i from 1 to the message_count
                set this_message to item i of these_messages
                tell (sender of this_message)
                    set theFromName to (extract name from it)
                    set theFromAddress to (extract address from it)
                end tell
                log "joel was here"


            end repeat
        end tell
    end perform mail action with messages
end using terms from

When I try to add a rule to run this script, I get to the file chooser, when I chose the file nothing happens, it just opens a the file in the script editor into a new window. My file ends in .scpt, I have tried putting it in com.apple.mail folder, in a sub folder under there, also in the original spot (in ScriptEditor folder), nothing seems to work.

This must be something silly and basic, any ideas?

Also is there any practical way to test this script, from what I have googled log will not work.

enter image description here


Solution

  • I finally figured this out, it has to be in the root of : ~/Library/Application Scripts/com.apple.mail

    It cant be in a sub folder, also I had a "-" in the name, that may have been an issue.

    Once I did this, the script was listed in the drop down.