脚本亮度如何降低?


1

我正在尝试创建一个可以将亮度调到最大或最小的AppleScript,但我不知道该怎么做。我正在尝试使用此脚本

    repeat 10 times
    tell application "System Events"
        key code 122
        delay 0.1
    end tell
end repeat

但没有任何反应。

Answers:


1

如果授予了允许UI脚本编写的必要可访问权限,则此脚本将通过“ 系统首选项”以编程方式调整屏幕亮度:

tell application "System Preferences"
    set current pane to pane id "com.apple.preference.displays"
    reveal anchor "displaysDisplayTab" of current pane
end tell

tell application "System Events" to tell ¬
    process "System Preferences" to tell ¬
    window 1 to tell ¬
    tab groups to tell ¬
    groups to tell ¬
    sliders to set its value to 0.5 -- 0.0 to 1.0

quit application "System Preferences"

您可以将您看到的值设置为0.0(最小亮度,显示关闭)和1.0(最大亮度)之间的任何十进制值。


1

如果我可能建议另一种选择,我会提供brightnesshttps://github.com/nriley/brightness或安装的命令brew install brightness

然后,您可以轻松切换到0(暗)和1(全功率)之间的任何亮度级别,brightness .5并且½-full。

brightness如果这是AppleScript解决方案,您可以从AppleScript 调用。


-1

通过苹果脚本尝试,这是可能的。

将显示器调暗至最低亮度:

repeat 32 times
    tell application "System Events"
        key code 107
    end tell
end repeat

要使显示屏亮度达到最大亮度:

repeat 32 times
    tell application "System Events"
        key code 113
    end tell
end repeat
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.