开发者

Is there a way to programmatically give focus to another running application in OSX?

开发者 https://www.devze.com 2023-02-08 17:31 出处:网络
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.

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

精彩评论

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