Is there a way to programmatically give focus to another running application in OSX?
I have a use case where I'd like my app to give f开发者_Python百科ocus to a specific running application. How do I do that?
Just send a chunk of AppleScript from your app, e.g.
tell application "Some other app"
activate
end tell
If you know the application's bundle id (and only need to target 10.6+), you can do:
NSRunningApplicatin *app = [NSRunningApplication runningApplicationWithBundleIdentifier:@"com.foo.someapp"];
[app activateWithOptions:NSApplicationActivateAllWindows];
If the other app has registered a custom URL scheme, you can launch it by submitted a URL with that scheme.
精彩评论