【发布时间】:2015-09-03 15:25:43
【问题描述】:
如何激活另一个已最小化的应用程序窗口?
如果前面还有其他窗口,它可以很好地使用 NSRunningApplication 类的 activateWithOptions 方法,但是这不适用于最小化的窗口。
如果你能帮助我,那就太好了。
干杯
【问题讨论】:
如何激活另一个已最小化的应用程序窗口?
如果前面还有其他窗口,它可以很好地使用 NSRunningApplication 类的 activateWithOptions 方法,但是这不适用于最小化的窗口。
如果你能帮助我,那就太好了。
干杯
【问题讨论】:
尝试摆弄 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);
可能有更好的方法,但它确实有效。
【讨论】:
【讨论】: