如何将此滑块值更改从 AppleScript 转换为 JavaScript [英] How to translate this slider value change from AppleScript to JavaScript

查看:28
本文介绍了如何将此滑块值更改从 AppleScript 转换为 JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This bit of AppleScript works. If I have the System Preferences Sound panel open, and run it in the Script Editor app, it changes the volume to be at 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

这试图成为同一件事,但失败了.有人知道怎么解决吗?

This, which tries to be the same thing, fails. Anyone know how to fix it?

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.实际上我正在尝试编写另一个应用程序的脚本,但这归结为问题.

It ends up setting it to 0. It seems I can only set the volume to 0 or 1. In reality I'm trying to script another application, but this boils down the problem.

推荐答案

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

As I noted in my comment, I'm 90% sure this is a bug. Here's a workaround:

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;
}

这篇关于如何将此滑块值更改从 AppleScript 转换为 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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