微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

| 我正在尝试创建一个AppleScript,用于设置“系统偏好设置”中“声音”菜单下“输入”类别的“输入音量”的值。 一个如何改变滑块的值?
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的任何描述,这是什么意思?     

解决方法

        您可以直接访问音量设置,而无需使用gui脚本。这些命令在applescript的标准附加osax中。要查看音量设置,可以使用此设置进行更改。注意,它在命令中需要单词“ get”。
get volume settings
查看这些结果,您可以看到输入音量是您可以访问的音量设置之一。这是一个介于0到100之间的值。这是设置方法...
set volume input volume 64
上面的命令有点奇怪,因为该命令中没有“ to \”字样。您没有将音量设置为“ to \”,这很奇怪。无论如何,祝你好运! 编辑:这是使用gui脚本访问它的方法。另外,如果您想知道错误代码,我在这里发布了一个脚本。有关最新版本,请参见文章#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
    ,        
set content of slider \"Input volume\" to x
    ,        滑块可以通过
increment
decrement
操作。因此,您可以重复直到达到您想要的水平。本示例将“声音效果警报”音量设置为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
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。