【问题标题】:Use AppleScript to change System Preferences without being visible?使用 AppleScript 在不可见的情况下更改系统偏好设置?
【发布时间】:2017-03-13 06:41:03
【问题描述】:

我想更改系统偏好设置中的设置而不让用户看到发生的事情。
如果我的脚本开头如下:

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.sound"
end tell

系统偏好设置窗口将显示给用户。
我想知道是否有办法在后台以某种方式执行此操作,或者至少保持窗口最小化。

(可以在in this question找到示例脚本。)

【问题讨论】:

  • 您要更改什么设置?
  • 今天,亮度设置,但我想要明天的通用解决方案。 :)

标签: macos applescript


【解决方案1】:

您可以使用命令行应用程序defaults 做您想做的事情,还有一些其他命令行应用程序可以操作其他系统内容,例如pmset

有些东西也可以使用脚本添加设置,例如系统卷可以使用标准添加设置,您也可以找到其他脚本添加来添加更多内容。

【讨论】:

  • 很酷!不确定这次它会帮助我,但对未来的问题很有用!
【解决方案2】:

您可以删除激活命令。系统事件可以在隐藏窗口中执行操作。

tell application "System Preferences"
    reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of tab group 1 of window 1
end tell
quit application "System Preferences"

如果您打开菜单,它们将是可见的。

tell application "System Preferences"
    reveal anchor "TTS" of pane "com.apple.preference.speech"
end tell
tell application "System Events" to tell process "System Preferences"
    tell pop up button 1 of tab group 1 of window 1
        delay 0.1
        click
        if value is "Alex" then
            click menu item "Kathy" of menu 1
        else
            click menu item "Alex" of menu 1
        end if
    end tell
end tell
quit application "System Preferences"

也可以使用brightness.c更改显示器的亮度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2016-09-15
    • 2021-05-28
    • 2019-02-23
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多