开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜