如何使用 Applescript 更改首选项窗格滑块值?
我正在尝试创建一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以直接访问音量设置,无需使用 GUI 脚本。这些命令位于 applescript 的标准添加 osax 中。要查看可以更改的音量设置,请使用它。请注意,命令中需要包含“get”一词。
查看这些结果,您可以看到输入音量是您可以访问的音量设置之一。它是一个从 0 到 100 的值。设置方法如下...
上面的命令有点奇怪,因为该命令中没有“to”一词。你没有将音量设置为“某物”,所以这很奇怪。无论如何祝你好运!
编辑:以下是如何使用 GUI 脚本访问它。另外,如果您想知道错误代码,我在此处发布了该脚本。请参阅帖子 #9 了解最新版本。
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.
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...
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.
可以使用
increment
和decrement
操作来操纵滑块。因此,您可以重复,直到达到您想要的水平。本示例将音效警报音量设置为 0.5Sliders can be manipulated with the
increment
anddecrement
actions. So, you can just repeat until it reaches the level you desire. This example sets the Sound Effects Alert volume to 0.5