【发布时间】:2019-09-26 21:32:56
【问题描述】:
我正在尝试编写一个 JXA 脚本,它垂直扩展当前应用程序的当前窗口的边界,使其从屏幕的顶部到达底部。如果我在 Automator 中将以下脚本作为“运行 JavaScript”快速操作运行,它可以工作:
var app = Application.currentApplication();
var window = app.windows[0];
var orig_bounds = window.properties().bounds;
var vertical_res =
Application("Finder").desktop.window.properties().bounds.height;
window.bounds = {
"x": orig_bounds.x,
"y": 0,
"width": orig_bounds.width,
"height": vertical_res
};
我希望将此脚本绑定到热键。当我在系统偏好设置 -> 键盘 -> 快捷方式 -> 服务 -> 常规中绑定它并尝试在某些应用程序处于活动状态时激活它(例如,iTerm 2),它不起作用,并且我收到错误消息:
The action “Run JavaScript” encountered an error: “Error on line 4: TypeError: undefined is not an object (evaluating 'window.properties')”
请注意,如果我修改脚本以始终在特定应用程序 (var app = Application("Google Chrome");) 上运行并在 Automator 中运行它,它可以工作。
【问题讨论】:
标签: javascript macos javascript-automation