Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
- let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
- let windowsList = windowsListInfo as NSArray? as? [[String: AnyObject]]
- let visibleWindows = windowsList?.filter{ $0["kCGWindowLayer"] as! Int == 0 }
- for window in visibleWindows! {
- let windowTitle = window["kCGWindowOwnerName"] as! String
- let windowNumber = window["kCGWindowNumber"] as! Int32
- if windowNumber == 124 { // Safari
- let nsWindow = NSApp.window(withWindowNumber: Int(windowNumber))
- nsWindow?.cascadeTopLeft(from: NSPoint(x: 100.0, y: 100.0))
- nsWindow?.setFrameTopLeftPoint(NSPoint(x: 100.0, y: 100.0))
- }
- }
- }
- NSApp.window(withWindowNumber: Int(windowNumber))
- let pid = window["kCGWindowOwnerPID"] as? Int32 {
- let app = NSRunningApplication(processIdentifier: pid)
- app?.activate(options: .activateIgnoringOtherApps)
Add Comment
Please, Sign In to add comment