-
-
Save frypf/66636117556fc9bdc092505d14edfe0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
// DETERMINE IF MISSION CONTROL IS CURRENTLY ACTIVE (tested on: Mojave, Monterey) | |
// • returns "true" (exit code 0) if Mission Control is active (all apps / single app / reveal desktop) | |
// • returns "false" (exit code 1) otherwise | |
// ––– | |
// • uses hackish check for existence of title-less window owned by Apple's Dock process | |
// • see: https://stackoverflow.com/a/66629065 | |
// ––– | |
// @frypf (Oct 2022) | |
import Cocoa | |
func missionControlActive() -> Bool { | |
let windowList = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as! [[String: Any]] | |
for window in windowList { | |
if | |
// window must be owned by "Dock" process | |
(window["kCGWindowOwnerName"] as? String) == "Dock", | |
// ensure the owner is not some other process named "Dock" (seems unlikely though) | |
let windowOwnerPID = window["kCGWindowOwnerPID"] as? pid_t, | |
let app = NSRunningApplication(processIdentifier: windowOwnerPID), | |
app.bundleIdentifier == "com.apple.dock", | |
// window must have no title | |
window["kCGWindowName"] == nil | |
{ | |
return true | |
} | |
} | |
return false | |
} | |
let result = missionControlActive() | |
print(result) | |
exit(result ? 0 : 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment