Wayne Hartman
Wayne Hartman

Reputation: 18477

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 focus to a specific running application. How do I do that?

Upvotes: 1

Views: 527

Answers (3)

Wevah
Wevah

Reputation: 28242

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];

Upvotes: 2

Paul R
Paul R

Reputation: 212969

Just send a chunk of AppleScript from your app, e.g.

tell application "Some other app"
    activate
end tell

Upvotes: 3

jlehr
jlehr

Reputation: 15597

If the other app has registered a custom URL scheme, you can launch it by submitted a URL with that scheme.

Upvotes: 0

Related Questions