如何激活其他最小化应用程序? OS X.

时间:2015-09-02 11:22:11

标签: macos cocoa

如何激活已最小化的其他应用程序的窗口?

如果前面有其他窗口,它可以很好地使用NSRunningApplication类的activateWithOptions方法,但是这不能用于最小化窗口。

如果你能够帮助我,那就太好了。

干杯

2 个答案:

答案 0 :(得分:1)

试图摆弄AppleEvents&想出了这个:

//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);

可能有更好的方法,但它有效。

答案 1 :(得分:0)

借助此answer,您可以进入最小化窗口。

现在,您可以在窗口上调用deminiaturize:将其打开。

我不确定这是否有效,让我知道它!