如何使用 applescript 按应用程序顺序枚举正在运行/打开的应用程序?
我的最终目标是确定最近使用的网络浏览器。即,用户可能同时运行 Safari 和 Firefox,但他们最近使用的是哪一个?
因此,我试图枚举打开的应用程序,按其窗口/可见性排序。
Cocoa / Applescript 是否提供了检索此信息的方法?
My end goal is to determine the most-recently-used web browser. I.e., a user may have both Safari and Firefox running, but which were they using most recently?
And so, I'm trying to enumerate the open apps, ordered by their window / visibility.
Does Cocoa / Applescript offer a way to retrieve this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 NSWorkspace 的
runningApplications
方法和 NSRunningApplication 的 < code>launchDate 属性让您接近您所需要的。如果此代码位在控制台中看起来像这样,请检查输出:
至于按某些标准进行排序,这实际上取决于您的实现。
一些注意事项:这些 api 是从 Snow Leopard (10.6) 开始引入的,
它们仅适用于用户可以看到的应用程序(在扩展坞中),而不是 UNIX 进程或管理/根守护程序或其他任何东西。
我还不确定 Applescript,但我希望您能够使用这些信息到达您需要去的地方。
You can use NSWorkspace's
runningApplications
method and NSRunningApplication'slaunchDate
property to get you close to what you need.Check out what the output if this code bit looks like in your console:
As for sorting on some criteria, that's really up to your implementation to do.
A couple caveats: these api's were introduced as of Snow Leopard (10.6) and
they only work on apps that the user can see (in the dock), not UNIX processes or admin/root daemons or whatever.
And I'm not certain about Applescript yet, but I'm hoping you'll be able to use this information to get to where you need to go.