【发布时间】:2011-09-04 02:00:44
【问题描述】:
我正在开发一个可以在 OSX 上移动和调整其他应用程序窗口大小的应用程序。 主应用程序是用 Cocoa 编写的,但大小调整部分是用 AppleScript 完成的,因为 Cocoa 似乎没有这种功能。
这是对 ActionScript 的常规调用的结果(作为字符串传递给 NSAppleScript):
tell application "TextEdit"
set currentWindow to the window id 5184
set bounds of the currentWindow to {2855, 218, 3790, 578}
end tell
Window ID 是使用 OSX 10.6 中引入的 CGWindowListCopyWindowInfo API 获得的。
这种方法适用于大多数窗口,但不适用于无法编写脚本的应用程序。 最突出的例子是 OSX 自己的 Preview。
我尝试使用此代码的变体“告诉”系统事件而不是预览
tell application "System Events"
set bounds of window 5184 to {1920, -502, 2855, 578}
end tell
但是,OSX 给了我一条错误消息:
"System Events got an error: Can’t set bounds of window 5184 to {1920, -502, 2855, 578}."
在尝试获取对窗口的引用时也会发生同样的情况:
tell application "System Events"
get window 5184
end tell
我已经仔细检查了窗口存在并且窗口 ID 是正确的。
在 OSX 上以编程方式调整不可脚本窗口大小的正确方法是什么? 我可以从moom等应用程序中看到它是可能的。
任何建议 - 无论是基于 Cocoa 还是基于 AppleScript 或完全其他的东西 - 都非常受欢迎。
【问题讨论】:
标签: cocoa macos resize window applescript