gpt4 book ai didi

macos - 如何激活其他最小化的应用程序?操作系统

转载 作者:行者123 更新时间:2023-12-03 16:40:39 29 4
gpt4 key购买 nike

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

如果前面有其他窗口,它可以很好地使用 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);

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

关于macos - 如何激活其他最小化的应用程序?操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32351790/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com