Skip to content

Instantly share code, notes, and snippets.

@stefanocoding
Created April 20, 2016 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanocoding/9168249a7eaaf5b228e532525b9c6cb0 to your computer and use it in GitHub Desktop.
Save stefanocoding/9168249a7eaaf5b228e532525b9c6cb0 to your computer and use it in GitHub Desktop.
import Cocoa
let workspace = NSWorkspace.sharedWorkspace()
let activeApps = workspace.runningApplications
for app in activeApps {
if app.active {
let listOptions = CGWindowListOption(arrayLiteral: CGWindowListOption.OptionOnScreenOnly)
let windowList : NSArray = CGWindowListCopyWindowInfo(listOptions, 0)!
for window in windowList {
if (window["kCGWindowOwnerName"] as! String) == app.localizedName {
let topWindow = window as! NSDictionary
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment