Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
  2. let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
  3. let windowsList = windowsListInfo as NSArray? as? [[String: AnyObject]]
  4. let visibleWindows = windowsList?.filter{ $0["kCGWindowLayer"] as! Int == 0 }
  5.  
  6. for window in visibleWindows! {
  7. let windowTitle = window["kCGWindowOwnerName"] as! String
  8. let windowNumber = window["kCGWindowNumber"] as! Int32
  9.  
  10. if windowNumber == 124 { // Safari
  11. let nsWindow = NSApp.window(withWindowNumber: Int(windowNumber))
  12. nsWindow?.cascadeTopLeft(from: NSPoint(x: 100.0, y: 100.0))
  13. nsWindow?.setFrameTopLeftPoint(NSPoint(x: 100.0, y: 100.0))
  14. }
  15. }
  16. }
  17.  
  18. NSApp.window(withWindowNumber: Int(windowNumber))
  19.  
  20. let pid = window["kCGWindowOwnerPID"] as? Int32 {
  21. let app = NSRunningApplication(processIdentifier: pid)
  22. app?.activate(options: .activateIgnoringOtherApps)
Add Comment
Please, Sign In to add comment