Created
March 23, 2023 18:24
-
-
Save dedeexe/3cd8ccf760125d692e2eec574269e46d to your computer and use it in GitHub Desktop.
A function to get the list of windows in MacOS using Swift
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
func getWindowsList() { | |
let options = CGWindowListOption(arrayLiteral: .optionOnScreenOnly) | |
let windowListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(1)) | |
let infoList = windowListInfo as! [[String: Any]] | |
let windowList = infoList.filter { (($0["kCGWindowLayer"] as? Int) ?? -1) == 0 } | |
for window in windowList { | |
print(window["kCGWindowOwnerName"]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment