如何使用 Applescript 更改首选项窗格滑块值? [英] How to use Applescript to Change Preference Pane Slider value?

查看:30
本文介绍了如何使用 Applescript 更改首选项窗格滑块值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 AppleScript,用于设置 Sound 菜单下 Input 类别的 Input Volume 值>系统偏好设置.

I'm trying to create an AppleScript for setting the value of Input Volume of the Input category under the Sound menu in System Preferences.

如何更改 Slider 的值?

How does one change the value of a 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 来找出如何按以下方式分层访问元素,

This doesn't seem to work. I also tried using Accessibility Inspector to find out how to hierarchically access the elements in the following manner,

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

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

That doesn't seem to be a correct way either.

这里出了什么问题?

编辑

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

So it returns an error. I couldn't find any description for error code -1700, what does it mean?

推荐答案

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

You can access the volume settings directly without using gui scripting. These commands are in the standard additions osax of applescript. To see the volume settings you can change use this. Notice it requires the word "get" in the command.

get volume settings

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

Looking at those results you can see that the input volume is one of the volume settings you can access. It's a value from 0 to 100. Here's how you can set it...

set volume input volume 64

上面的命令有点奇怪,因为该命令中没有to"这个词.你没有将音量设置为",所以很奇怪.总之祝你好运!

The above command is a little strange because there is no "to" word in that command. You're not setting the volume "to" something so it's strange. Anyway Good luck!

以下是使用 gui 脚本访问它的方法.另外,如果你想知道错误代码,我在这里发布了一个脚本.有关最新版本,请参阅帖子 #9.

Here's how to access it using gui scripting. Also if you want to know the error codes, I posted a script for that here. See post #9 for the latest version.

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

这篇关于如何使用 Applescript 更改首选项窗格滑块值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆