使用辅助功能 API 关闭另一个应用程序的所有窗口
我已经知道如何在 Objective-C 中使用 Mac OSX Accessibility API 来重新定位另一个正在运行的应用程序的窗口,而无需使用任何类型的脚本桥。
现在,我想使用相同的 Accessibility API(同样,没有任何脚本桥)来关闭另一个正在运行的应用程序的所有打开的窗口。
我想用 Objective-C 编写的代码应该与这个 AppleScript 代码做同样的事情:
tell application "TheApplication"
close every window
end tell
我猜这是可能的,因为它在 AppleScript 中是允许的。
I already know how to use the Mac OSX Accessibility API within Objective-C to reposition windows of another running application, without the use of any kind of scripting bridge.
Now, I want to use this same Accessibility API (again, without any scripting bridge) to close all the open windows of another running application.
The code that I want to write in Objective-C should do the same thing as this AppleScript code:
tell application "TheApplication"
close every window
end tell
I would guess that this is possible, because it's permitted within AppleScript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的解决方案...
Here's my solution ...
有一个 Cocoa 类, < code>NSApplescript,它允许您从 ObjC 代码中编译并运行 Applescript。你还没有真正说出为什么你不想使用AS。由于您已经获得了可以执行您想要的操作的脚本,因此您可以立即使您的程序运行并使用它:
稍后再担心意识形态的纯度或性能。
There's a Cocoa class,
NSApplescript
, that lets you compile and run Applescript from within your ObjC code. You haven't really said why you don't want to use AS. Since you've already got the script that does what you want, you can make your program work right now and just use it:Worry about ideological purity or performance later.