2

How do I activate a window of another application which has been minimised?

If there are other windows in front it works pretty good with the activateWithOptions method of the NSRunningApplication class, but this won't work with a minimised window.

It'd be great if you were able to help me.

Cheers

raphael_mav
  • 580
  • 6
  • 23

2 Answers2

2

Tried fiddling with AppleEvents & came up with this:

//Get the PID for a running application.
NSRunningApplication* runningApp = [[NSRunningApplication
                                     runningApplicationsWithBundleIdentifier:@"com.apple.Safari"]
                                        lastObject];
pid_t                 appPID     = [runningApp processIdentifier];

//Create event target.
NSAppleEventDescriptor* targetDescriptor
 = [NSAppleEventDescriptor descriptorWithDescriptorType:typeKernelProcessID
                                                  bytes:&appPID
                                                 length:sizeof(appPID)];

//Create "reopen" event.
NSAppleEventDescriptor* reopenDescriptor
 = [NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass
                                            eventID:kAEReopenApplication
                                   targetDescriptor:targetDescriptor
                                           returnID:kAutoGenerateReturnID
                                      transactionID:kAnyTransactionID];

//Create "activate" event.
NSAppleEventDescriptor* activateDescriptor
 = [NSAppleEventDescriptor appleEventWithEventClass:kAEMiscStandards
                                            eventID:kAEActivate
                                   targetDescriptor:targetDescriptor
                                           returnID:kAutoGenerateReturnID
                                      transactionID:kAnyTransactionID];

//Send "activate" followed by "reopen".
AESendMessage([activateDescriptor aeDesc], NULL, kAENoReply, kAEDefaultTimeout);
AESendMessage([reopenDescriptor   aeDesc], NULL, kAENoReply, kAEDefaultTimeout);

There may be a better way, but it works.

-1

With help of this answer, you may be able to get to the minimized window.

Now you can call deminiaturize: on the window to open it up.

I am not sure if this works, let me know about it!

Community
  • 1
  • 1
mangerlahn
  • 4,746
  • 2
  • 26
  • 50
  • I didn't try it because i already had the RunningApplication which the other answer used, so i didn't had to rewrite a lot of code. Although thank you very much for your help!!! – raphael_mav Sep 03 '15 at 07:44