javascript-automation - 使用 JXA 获取所有正在运行的全屏应用程序(或空间)的列表
问题描述
鉴于有应用程序以全屏模式运行,我想知道是否有办法使用 JXA 列出它们。类似于下面的内容,但适用于所有正在运行的全屏应用程序。
var list = Application('System Events').applicationProcesses.where({ backgroundOnly: false }).windows.name();
用例:我正在尝试创建一个 Alfred 工作流来按名称导航全屏应用程序。
谢谢!
解决方案
干得好:
ObjC.import('CoreGraphics');
unwrap = ObjC.deepUnwrap.bind(ObjC);
(function run() {
const bounds = x => ['X', 'Y', 'Width', 'Height'].map(k => x.kCGWindowBounds[k]);
const windowInfo = unwrap($.CGWindowListCopyWindowInfo(
$.kCGWindowListOptionAll,
$.kCGNullWindowID)),
applicationWindows = windowInfo.filter(x => x.kCGWindowLayer==0),
menubar = windowInfo.filter(x => x.kCGWindowName=='Menubar')[0],
desktop = windowInfo.filter(x => x.kCGWindowName=='Desktop')[0],
fullframe = bounds(desktop);
return applicationWindows.filter(x => {
return bounds(x).reduce((ξ, y, i) => {
return ξ && (y==fullframe[i]);
}, true);
}).map(x => x.kCGWindowOwnerName);
})();
推荐阅读
- c# - 使用异步/等待 - C#
- python - python中是否有一个函数可以替换字符串中的字符,反之亦然?
- c++ - c++ 可变参数宏可以读取分布在多行的参数吗?
- ruby - 我在 Ruby on Rails 中使用关联时遇到问题
- ffmpeg - ffmpeg:[NULL @ 0x5578f5fc0580] 无法为 '[out]' [out] 找到合适的输出格式:参数无效
- wordpress - Letsencrypt、nginx-proxy wordpress 和 docker 问题
- dll - libxml2 依赖项,但是当程序启动时,它要求使用 mingw32 编译的 libxml2-2
- automation - 开发人员调查,估计架构师/开发人员设置基本软件架构、系统安全和集成所花费的时间
- sql - SQL 代码仅获取平均价值高于所有产品的全球平均价格的产品
- rust - 如何在 Rust 中使用 cargo-raze 为 Bazel 生成包 BUILD 文件?