objective-c - 如何检查最前面的应用程序是否全屏?

标签 objective-c xcode macos cocoa fullscreen

我需要知道最前面的应用程序是否处于全屏状态。
这是我必须检查的内容(我知道 NSApplicationPresentationOptions 仅适用于 NSApplication,但我不知道如何使用 NSRunningApplication) :

NSArray *activeApps = [[[NSWorkspace sharedWorkspace] runningApplications] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isActive==YES && bundleIdentifier!=%@", MY_BUNDLE_IDENTIFIER]];
if ([activeApps count] > 0){
    NSApplicationPresentationOptions opts = [[activeApps objectAtIndex:0] presentationOptions];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(setupPlayer) userInfo:nil repeats:YES];
    if (opts & NSApplicationPresentationFullScreen) {
        //Do something
    }    
}

因此,当我运行代码时,我显然收到以下错误,因为 [activeApps objectAtIndex:0]NSRunningApplication :

-[NSRunningApplication presentationOptions]: unrecognized selector sent to instance...

关于如何修复它并检查最前面的应用程序是否处于全屏状态有什么想法吗?或者还有其他替代方法可以执行此操作吗?

最佳答案

您可以使用 applescript 来检查最前面的应用程序是否全屏。

脚本可以是这样的,

1) 获取应用程序最前面的窗口。 2) 获取该窗口的属性值“AXFullScreen”。

这会让您知道最前面的应用程序是否全屏。'

希望对你有帮助!!!

关于objective-c - 如何检查最前面的应用程序是否全屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14115668/

相关文章:

objective-c - 将 NSString 写入文件

c++ - 如何将 UTF8 std::string 转换为 NSString?

iphone - Xcode 验证错误 : Unexpected value for key: CFBundleIconFile is not a string

objective-c - 在 Objective C 中,什么相当于在 C 中传递函数指针?

objective-c - SMJobSubmit() 能否用于执行由 SMJobBless 安装的特权助手?

swift - 无法添加 Xcode 8 桥接头

git - 删除名为 "~"的文件并从 git 取消暂存

macos - Mac OS X/RSS低吼通知

macos - 如何判断菜单项是否为 'checked' ?

objective-c - Objective C 运行时如何查找已定义的消息?