hepcat72
hepcat72

Reputation: 1124

Applescript to activate Mail Rule seems to work, but GUI says otherwise

I wrote a quick script that I plan to run automatically on a schedule from a calendar (or a crontab/osascript entry). I haven't tried a script to mess with Mail rules before, and in debugging the code, I noted something unexpected. Let me show the code and then describe what I see happen:

tell application "Mail"
    repeat with arule in rules
        if name of arule is "RT - On Duty Colorer" then
            display dialog "Looking at rule: " & name of arule
            if enabled of arule is false then
                set enabled of arule to true
                display dialog "Enabled was false"
            else
                display dialog "Already enabled"
            end if
        end if
    end repeat
end tell

If I manually activate or deactivate the target mail rule, I see the expected "Enabled was false" or "Already enabled" dialog message.

And if I manually deactivate the rule and run the script twice, I again see the expected dialog messages: first I get the "Enabled was false", then I see "Already enabled" on the second run...

BUT, what I didn't expect was the the checkbox next to the target rule never shows that the rule's enabled state has been changed by the script:

enter image description here

I tried quitting Mail and restarting it to see if the active checkbox would update to reflect the state that the script set. So I'm not sure if I can rely on this script to activate the mail rule...

Has anyone encountered this issue? Is it just a display issue? Will the script-activated rule run as I intend? Is there anything I should change in my script to make the checkbox display as checked?

Upvotes: 0

Views: 81

Answers (1)

Elio Labbia
Elio Labbia

Reputation: 9

I believe it's just a display issue. I noticed the same behaviour with the Firewall. If you approach it from the command line while the Security & Privacy > Firewall pane is opened, it will not switch on/off visually, while the command shows it's otherwise working:

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
Firewall is disabled. (State = 0)
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
Firewall is enabled. (State = 1)

Upvotes: 1

Related Questions