【问题标题】:How to use Applescript to Change Preference Pane Slider value?如何使用 Applescript 更改首选项窗格滑块值?
【发布时间】:2011-09-03 20:14:52
【问题描述】:

我正在尝试创建一个 AppleScript 来设置 声音 菜单下 Input 类别的 Input Volume 的值>系统偏好设置

如何改变 Slider 的值?

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
if UI elements enabled then
    try
        tell application process "System Preferences"
            tell tab group 1 of window "Sound"
                click radio button "Input"
                select row 1 of table 1 of scroll area 1
                set selected of row 1 of table 1 of scroll area 1 to true
                set deviceselected to "Microphone"
                set slider "Input Volume" of group "Input Volume" of tab group "Input" to 0
                select row 2 of table 1 of scroll area 1
                set selected of row 2 of table 1 of scroll area 1 to true
                set deviceselected to "Microphone"
                set slider "Input Volume" of group "Input Volume" of tab group "Input" to 0


            end tell
        end tell
    end try
end if
end tell

这似乎不起作用。 我还尝试使用 Accessibility Inspector 来了解如何以以下方式分层访问元素,

 value of slider of group "Input volume" of tab group "Input" of window "Sound" 

这似乎也不是正确的方法。

这里有什么问题?

编辑

set content of slider "Input volume" of tab group "Input" of window "Sound" of tab group     1 of window "Sound" of application process "System Preferences" to 0
        --> error number -1700 from content of slider "Input volume" of tab group "Input" of window "Sound" of tab group 1 of window "Sound" of application  **

所以它返回一个错误。我找不到错误代码-1700的任何描述,这是什么意思?

【问题讨论】:

    标签: macos scripting applescript


    【解决方案1】:

    您可以直接访问音量设置,而无需使用 gui 脚本。这些命令在 applescript 的标准添加 osax 中。要查看音量设置,您可以使用它进行更改。请注意,它需要在命令中使用“get”一词。

    get volume settings
    

    查看这些结果,您可以看到输入音量是您可以访问的音量设置之一。这是一个从 0 到 100 的值。这是您可以设置它的方法...

    set volume input volume 64
    

    上面的命令有点奇怪,因为该命令中没有“to”字样。您没有将音量“设置为”某事,所以这很奇怪。总之祝你好运!

    编辑: 以下是使用 gui 脚本访问它的方法。另外,如果您想知道错误代码,我发布了该here 的脚本。有关最新版本,请参阅帖子 #9。

    tell application "System Preferences"
        activate
        set current pane to pane "com.apple.preference.sound"
    end tell
    
    tell application "System Events"
        tell application process "System Preferences"
            tell tab group 1 of window "Sound"
                click radio button "Input"
                get value of slider 1 of group 2
            end tell
        end tell
    end tell
    

    【讨论】:

    • 行得通!谢谢你。这解决了问题,但我仍然想知道如何直接访问 Slider 值,例如,出于好奇,如何分层访问其值并对其进行操作。
    • 出于好奇,我在帖子中添加了 gui 脚本技术。
    【解决方案2】:
    set content of slider "Input volume" to x
    

    【讨论】:

    • 看来这不能解决问题。我也试过这个:code将窗口“声音”的选项卡组“输入”的滑块“输入音量”的内容设置为 0 code 也不起作用。
    • 也不这样做:将选项卡组“输入”的“输入音量”组的滑块“输入音量”设置为0
    【解决方案3】:

    滑块可以通过incrementdecrement 操作进行操作。所以,你可以重复,直到它达到你想要的水平。此示例将声音效果警报音量设置为 0.5

    tell application "System Preferences"
    
        tell anchor "effects" of pane "com.apple.preference.sound" to reveal
    
        tell application "System Events" to tell process "System Preferences"
            set s to slider "Alert volume:" of tab group 1 of window 1
            repeat while value of s is less than 0.5
                increment s
            end repeat
            repeat while value of s is greater than 0.5
                decrement s
            end repeat
    
        end tell
    
    end tell
    

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 2015-11-10
      • 2020-07-22
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多