OSX - Detect when Finder is started

余生颓废 提交于 2019-12-12 02:35:08

问题


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

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


回答1:


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".



来源:https://stackoverflow.com/questions/30033894/osx-detect-when-finder-is-started

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!