问题
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