OSX-检测何时启动Finder [英] OSX - Detect when Finder is started
问题描述
我的应用程序如何知道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屋!