SPB Git

Repository Public

window-shot.swift 1.1 KB 15 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Scripts/window-shot.swift3// Description: Captures the frontmost window of a named app to a PNG (evidence for visual checks).4// Usage: swift Scripts/window-shot.swift "SP Vault Dev" docs/screenshots/mac-main.png   (the app must have "Hide from screen capture" off)5import CoreGraphics6import Foundation7let args = CommandLine.arguments8guard args.count == 3 else { print("usage: window-shot <AppName> <out.png>"); exit(2) }9let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []10let wins = list.filter { ($0["kCGWindowOwnerName"] as? String) == args[1] && ($0["kCGWindowLayer"] as? Int) == 0 }11guard let win = wins.first, let id = win["kCGWindowNumber"] as? Int else { print("no window for \(args[1])"); exit(1) }12print("window \(id) \(win["kCGWindowBounds"] ?? "") title=\(win["kCGWindowName"] ?? "")")13let p = Process(); p.executableURL = URL(fileURLWithPath: "/usr/sbin/screencapture"); p.arguments = ["-l", String(id), "-o", "-x", args[2]]14try! p.run(); p.waitUntilExit(); print("saved \(args[2])")15
Files main
Menu

Theme