OSX-检测何时启动Finder [英] OSX - Detect when Finder is started

查看:77
本文介绍了OSX-检测何时启动Finder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序如何知道Finder已启动?有什么事件可以帮助您解决这个问题吗?

How can my app know that Finder has started? Is there any event that could help with this?

我考虑过枚举进程并寻找Finder,但这似乎太繁重,无法每隔X秒执行一次.还有其他办法吗?

I thought about enumerating processes and look for Finder but this seems too heavy to do every X seconds. Is there any other way?

推荐答案

您可以观察NSWorkspace发布到其通知中心(-[NSWorkspace notificationCenter])的通知.例如,当启动GUI应用程序时,它将发布NSWorkspaceDidLaunchApplicationNotification.该通知的userInfo词典在键NSWorkspaceApplicationKey下具有新启动的应用程序的NSRunningApplication实例.您可以检查其中的bundleIdentifier值是否等于"com.apple.finder".

You can observe the notifications that NSWorkspace posts to its notification center (-[NSWorkspace notificationCenter]). For example, it posts NSWorkspaceDidLaunchApplicationNotification when a GUI app is launched. That notification's userInfo dictionary has, under the key NSWorkspaceApplicationKey, an instance of NSRunningApplication for the newly-launched app. You can check the bundleIdentifier of that to see if it equals "com.apple.finder".

这篇关于OSX-检测何时启动Finder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆