如何翻译这个滑块值的变化,从AppleScript的为JavaScript [英] How to translate this slider value change from AppleScript to JavaScript

查看:330
本文介绍了如何翻译这个滑块值的变化,从AppleScript的为JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的AppleScript的该位工作。如果我有系统preferences音响面板打开,在脚本编辑器的应用程序运行它,它改变音量是在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天全站免登陆