0

这一点 AppleScript 有效。如果我打开了系统偏好设置声音面板,并在脚本编辑器应用程序中运行它,它会将音量更改为 50%。

tell application "System Events"
    tell process "System Preferences"
        set v to value of slider 0 of window 0
        log v
        set value of slider 0 of window 0 to 0.5
    end tell
end tell

这试图成为同一件事,但失败了。谁知道怎么修它?

var se = Application("System Events");
var spp = se.processes["System Preferences"];

spp.windows[0].sliders[0].value = 0.5

var curr = spp.windows[0].sliders[0].value();
console.log("Current value: " + curr + " - " + typeof(curr));

最终将其设置为 0。似乎我只能将音量设置为 0 或 1。实际上,我正在尝试编写另一个应用程序的脚本,但这归结为问题。

4

1 回答 1

1

正如我在评论中指出的那样,我 90% 确定这是一个错误。这是一个解决方法:

app = Application.currentApplication();
app.includeStandardAdditions = true;
try {
app.doShellScript('osascript -e \'tell application "System Events" to set value of slider 0 of window 0 of process "System Preferences" to 0.2\'');
} catch (error ) {
-1;
}
于 2015-02-21T00:14:14.357 回答