如何将此滑块值更改从 AppleScript 转换为 JavaScript

编程入门 行业动态 更新时间:2024-10-16 22:16:57
本文介绍了如何将此滑块值更改从 AppleScript 转换为 JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这一点 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 13:53:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将此   转换为   滑块   AppleScript   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!