【问题标题】:How to activate other minimised Application? OS X如何激活其他最小化的应用程序?操作系统
【发布时间】:2015-09-03 15:25:43
【问题描述】:

如何激活另一个已最小化的应用程序窗口?

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

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

干杯

【问题讨论】:

    标签: macos cocoa


    【解决方案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);
    

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

    【讨论】:

      【解决方案2】:

      answer 的帮助下,您也许能够进入最小化窗口。

      现在您可以在窗口上拨打deminiaturize: 将其打开。

      我不确定这是否有效,请告诉我!

      【讨论】:

      • 我没有尝试,因为我已经有了另一个答案使用的 RunningApplication,所以我不必重写很多代码。虽然非常感谢您的帮助!!!
      猜你喜欢
      • 2016-08-15
      • 1970-01-01
      • 2018-07-08
      • 2015-10-27
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      相关资源
      最近更新 更多