0
votes

I am trying to the run the following in Big Sur Mac and Automator just gets really slow. There are some answers on this for Catalina and Mojave but this doesn't seem to work. I'm new to Automator and applescript so apologies if this is really simple..

`on run {input, parameters}`

    # quit system preferences if running
    if running of application "System Preferences" then
        try
            tell application "System Preferences" to quit
        on error
            do shell script "killall 'System Preferences'"
        end try
    end if

    # wait for system preferences to quit
    with timeout of 10 seconds
        repeat while running of application "System Preferences" is true
            delay 0.01
        end repeat
    end timeout

    # switch to correct anchor
    tell application "System Preferences" to reveal anchor "Seeing_ColorFilters" of pane "Accessibility"
    #tell application "System Preferences" to activate
    #get the name of every anchor of pane "Accessibility" of application "System Preferences"

    tell application "System Events" to tell process "System Preferences" to tell window "Accessibility"
        #return UI elements of tab group 1 of group 1
        with timeout of 10 seconds
            repeat until exists checkbox "Enable Color Filters" of tab group 1 of group 1
                delay 0.01
            end repeat
        end timeout
        click the checkbox "Enable Color Filters" of tab group 1 of group 1
    end tell

    tell application "System Preferences" to quit

    return

    return input
`end run`
1
How slow are we talking about? It runs fine/fast when I try it on a 2018 mbp with 16GB of RAM with Big Sur. - user3579815

1 Answers

0
votes

I'm not sure why the given script fails — it fails on Catalina too, incidentally — but I'm suspicious of that first repeat loop, which looks like a recipe for disaster. But in any case, raw first two sectons of the script aren't necessary, so we can just skip over them. Try this:

tell application "System Preferences" to reveal anchor "Seeing_ColorFilters" of pane "Accessibility"

tell application "System Events"
    tell process "System Preferences"'s first window's first group's first tab group
        click checkbox "Enable Color Filters"
        tell first pop up button
            click
            -- if necessary, uncomment the following line to allow time for the menu to open
            -- delay 0.1
            tell its menu
                click menu item 1
            end tell
        end tell
    end tell
end tell

tell application "System Preferences" to quit