如何使用 Applescript 更改首选项窗格滑块值?

2024-01-25

我正在尝试创建一个 AppleScript 来设置输入音量 of the Input类别下的Sound菜单中系统偏好设置.

如何改变 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

这似乎不起作用。 我也尝试过使用无障碍检查员了解如何通过以下方式分层访问元素,

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

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

这是怎么回事?

EDIT

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的任何描述,这是什么意思?


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

get volume settings

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

set volume input volume 64

上面的命令有点奇怪,因为该命令中没有“to”一词。你没有将音量设置为“某物”,所以这很奇怪。无论如何祝你好运!

EDIT:以下是如何使用 GUI 脚本访问它。另外,如果您想知道错误代码,我为此发布了一个脚本here https://archive.md/GyJ3a。最新版本请参见帖子 #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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Applescript 更改首选项窗格滑块值? 的相关文章

随机推荐