user1828883
user1828883

Reputation: 51

Window Constantly Wants To Be On Top Of Others - Xcode

My app has buttons that open automator workflows like this:

- (IBAction)actionname:(id)sender {
    NSTaskname = [[NSTask alloc] init];
    [NSTaskname setLaunchPath:@"/usr/bin/automator"];
    NSArray *arguments;
    arguments = [NSArray arrayWithObjects:@"/Applications/appname.app/Contents/Resources/workflowname.workflow", nil];
    [NSTaskname setArguments:arguments];
    [NSTaskname launch];                                                                             
}

The only problem is, that every single one appears behind the window of my app. Also, one workflow launches another app which also appears behind the window.

How can I fix this?

Upvotes: 0

Views: 117

Answers (1)

regulus6633
regulus6633

Reputation: 19040

You can probably use NSRunningApplication to bring your NSTask process to the front with its PID like this...

NSRunningApplication* app = [NSRunningApplication runningApplicationWithProcessIdentifier:[NSTaskname processIdentifier]];
[app activateWithOptions: NSApplicationActivateAllWindows];

And if you need to activate a specific application, for example your workflow that launches another app, then you could do this using the application's bundle identifier. This example will activate Safari.

NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.Safari"];
[(NSRunningApplication*)[apps objectAtIndex:0] activateWithOptions: NSApplicationActivateAllWindows];

Upvotes: 2

Related Questions