Applescript Mojave 切换辅助功能灰度开/关 [英] Applescript Mojave Toggle Accessibility Grayscale On/Off
本文介绍了Applescript Mojave 切换辅助功能灰度开/关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个定期运行的脚本,用于使用 Applescript 打开/关闭灰度.它在 High Sierra 上运行良好,但当我在 Mojave 使用它时抛出异常.
I have a script I run periodically to toggle grayscale on/off with Applescript. It runs fine on High Sierra but throw an exception when I use it was 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"
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/有谁知道如何解决这个问题?
Does Mojave still support Applescript/Would anyone know how to fix this?
推荐答案
这对我有用 使用 OS Mojave
This works for me Using OS 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
这篇关于Applescript Mojave 切换辅助功能灰度开/关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文