Skip to content

Instantly share code, notes, and snippets.

@chanakasan
Created May 16, 2020 05:56
Show Gist options
  • Save chanakasan/15ebc5a4c11c25abd9bb719a81e0bad0 to your computer and use it in GitHub Desktop.
Save chanakasan/15ebc5a4c11c25abd9bb719a81e0bad0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env osascript -l JavaScript
/**
* A JXA script to list all the fullscreen windows.
* Note: In macOS Mojave this method lists all the maximized windows as well.
* So we don't know which ones are fullscreen.
*/
ObjC.import('CoreGraphics');
const unwrap = ObjC.deepUnwrap.bind(ObjC);
const getBounds = x => ['X', 'Y', 'Width', 'Height'].map(k => x.kCGWindowBounds[k]);
const windowInfo = unwrap($.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID))
const applicationWindows = windowInfo.filter(x => x.kCGWindowLayer === 0 && x.kCGWindowName)
const menubar = windowInfo.filter(x => x.kCGWindowName === 'Menubar')[0]
const desktop = windowInfo.filter(x => x.kCGWindowName === 'Desktop')[0]
const fullFrameSize = getBounds(desktop);
const results = applicationWindows.filter(x => {
const windowSize = getBounds(x)
if (JSON.stringify(windowSize) === JSON.stringify(fullFrameSize)) {
return true
}
return false
}).map(x => ({
app: x.kCGWindowOwnerName,
pid: x.kCGWindowOwnerPID,
winTitle: x.kCGWindowName,
winInfo: x,
}))
console.log("[DEBUG] results =", JSON.stringify(results, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment