Question

I'm trying to open the app Spotify, and move it to the background. I can easily open Spotify with

SpotifyApplication *Spotify = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
[Spotify activate];

But Spotify goes to the foreground, covering my windows. With iTunes, I can use

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
[iTunes run];

However it's an iTunes specific method. Is this possible?

Était-ce utile?

La solution

Would you be willing to use NSAppleScript to do it?

NSAppleScript *script = [[NSAppleScript alloc]
    initWithSource:@"tell app \"Spotify\" to launch"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
if (errorInfo) {
    NSLog(@"error: %@", errorInfo);
}

You have to use the application name, not its bundle ID.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top