Applescript Mojave Toggle Доступность Оттенки серого вкл / выкл - PullRequest
0 голосов
/ 01 октября 2018

У меня есть скрипт, который я периодически запускаю для включения / выключения оттенков серого с помощью Applescript.На High Sierra он работает нормально, но, когда я использую его, было исключение - Мохаве.

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell

tell application "System Events" to tell process "System Preferences"
    delay 0.5 # Needed or else script fails
    set theCheckbox to checkbox "Use grayscale" of window "Accessibility"
    tell theCheckbox
        # If the checkbox is not checked, check it to turn grayscale on
        if not (its value as boolean) then
            set checked to true
            click theCheckbox
        else # else turn grayscale off
            set checked to false
            click theCheckbox
        end if
    end tell
end tell

tell application "System Preferences"
    quit
end tell

Исключение составляет:

System Events got an error: Can’t get checkbox "Use grayscale" of window "Accessibility" of process "System Preferences". (-1728)

Поддерживает ли Mojave Applescript / Кто-нибудь знает, как это исправить?

1 Ответ

0 голосов
/ 04 октября 2018

Это работает для меня, используя ОС Mojave

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell

tell application "System Events" to tell process "System Preferences"
    repeat while not (exists of checkbox "Use grayscale" of group 1 of window "Accessibility")
        delay 0.1
    end repeat
    set theCheckbox to checkbox "Use grayscale" of group 1 of window "Accessibility"
    tell theCheckbox
        # If the checkbox is not checked, check it to turn grayscale on
        if not (its value as boolean) then
            set checked to true
            click theCheckbox
        else # else turn grayscale off
            set checked to false
            click theCheckbox
        end if
    end tell
end tell

tell application "System Preferences"
    quit
end tell
...