SPB Git

Repository Public

winid.swift 1.1 KB 22 lines swift

1// ORIX DJ2// File: Scripts/tools/winid.swift3// Description: Prints the window IDs (largest first) of on-screen windows owned by a process, for screencapture -l.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import CoreGraphics8import Foundation910guard CommandLine.arguments.count > 1, let pid = Int(CommandLine.arguments[1]) else { exit(2) }11let layerFilter = CommandLine.arguments.count > 2 ? Int(CommandLine.arguments[2]) : 012let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []13let mine = list.filter { ($0[kCGWindowOwnerPID as String] as? Int) == pid && (layerFilter == nil || ($0[kCGWindowLayer as String] as? Int) == layerFilter) }14func area(_ w: [String: Any]) -> Double {15    let b = w[kCGWindowBounds as String] as? [String: Double] ?? [:]16    return (b["Width"] ?? 0) * (b["Height"] ?? 0)17}18for w in mine.sorted(by: { area($0) > area($1) }) {19    let b = w[kCGWindowBounds as String] as? [String: Double] ?? [:]20    print(w[kCGWindowNumber as String] as? Int ?? 0, Int(b["Width"] ?? 0), Int(b["Height"] ?? 0), w[kCGWindowName as String] as? String ?? "")21}22
Files main
Menu

Theme