gpt4 book ai didi

cocoa - 在 Mac 上以编程方式隐藏全屏应用程序

转载 作者:行者123 更新时间:2023-12-03 17:51:29 24 4
gpt4 key购买 nike

我有这段代码,可以隐藏所有正在运行的应用程序的窗口(Finder 除外)。

NSArray *apps = [[NSWorkspace sharedWorkspace] runningApplications];

for (NSRunningApplication *app in apps) {
if([app.bundleIdentifier.lowercaseString isEqualToString:@"com.apple.finder"]) {
[app activateWithOptions:NSApplicationActivateAllWindows|NSApplicationActivateIgnoringOtherApps];
} else {
[app hide];
}
}

不过,它对于非全屏窗口来说工作正常。

如何隐藏所有全屏窗口?

这也不起作用

[NSWorkspace.sharedWorkspace hideOtherApplications];

最佳答案

我就是这样做的:

// Create a tiny window on each screen to force all the full screen windows to get out of the way
for (NSScreen *screen in [NSScreen screens]) {
NSRect dummyFrame = {0,0,1,1};

NSWindow *dummyWindow = [[NSWindow alloc] initWithContentRect:dummyFrame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:screen];

NSView *dummyView = [[NSView alloc] initWithFrame:dummyFrame];
[dummyWindow setContentView: dummyView];
[dummyWindow makeKeyAndOrderFront:self];
}

// Now hide all the windows except for Finder's
NSArray *apps = [[NSWorkspace sharedWorkspace] runningApplications];

for (NSRunningApplication *app in apps) {
if([app.bundleIdentifier.lowercaseString isEqualToString:@"com.apple.finder"]) {
[app activateWithOptions:NSApplicationActivateAllWindows|NSApplicationActivateIgnoringOtherApps];
} else {
[app hide];
}
}

关于cocoa - 在 Mac 上以编程方式隐藏全屏应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25458124/

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