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

发布于 2024-11-10 02:11:48 字数 1753 浏览 2 评论 0原文

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

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

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

这是怎么回事?

编辑

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

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.

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

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.

What's wrong here?

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  **

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不念旧人 2024-11-17 02:11:48

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

get volume settings

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

set volume input volume 64

上面的命令有点奇怪,因为该命令中没有“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

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

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

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!

EDIT: 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
记忆之渊 2024-11-17 02:11:48

可以使用 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

Sliders can be manipulated with the increment and decrement actions. So, you can just repeat until it reaches the level you desire. This example sets the Sound Effects Alert volume to 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
德意的啸 2024-11-17 02:11:48
set content of slider "Input volume" to x
set content of slider "Input volume" to x
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文