SPB Git

Repository Public License

winid.swift 4.6 KB 105 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Monitor9// File             : Scripts/tools/winid.swift10// Description      : Prints the window IDs (largest first) of on-screen windows11//                    owned by a process, for screencapture -l.12// Module           : Scripts13// Repository       : https://git.spboucher.ai/orix-monitor14// Created          : 2026-11-2115// Last Modified    : 2026-11-2116//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author           : Simon-Pierre Boucher22// Position         : Professor of Finance23// Institution      : Université du Québec en Outaouais (UQO)24// Department       : Département des sciences administratives25// Organization     : SP Boucher26//27// Website          : https://spboucher.ai28// Git              : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General          : info@spboucher.ai35// Professional     : contact@spboucher.ai36// Direct           : simon@spboucher.ai37// Research         : research@spboucher.ai38// Development      : dev@spboucher.ai39// Support          : support@spboucher.ai40// Security/Admin   : admin@spboucher.ai41// Notifications    : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification   : Public68// Distribution     : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License          : Proprietary, all rights reserved (see license file)82// License File     : LICENSE83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import CoreGraphics91import Foundation9293guard CommandLine.arguments.count > 1, let pid = Int(CommandLine.arguments[1]) else { exit(2) }94let layerFilter = CommandLine.arguments.count > 2 ? Int(CommandLine.arguments[2]) : 095let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []96let mine = list.filter { ($0[kCGWindowOwnerPID as String] as? Int) == pid && (layerFilter == nil || ($0[kCGWindowLayer as String] as? Int) == layerFilter) }97func area(_ w: [String: Any]) -> Double {98    let b = w[kCGWindowBounds as String] as? [String: Double] ?? [:]99    return (b["Width"] ?? 0) * (b["Height"] ?? 0)100}101for w in mine.sorted(by: { area($0) > area($1) }) {102    let b = w[kCGWindowBounds as String] as? [String: Double] ?? [:]103    print(w[kCGWindowNumber as String] as? Int ?? 0, Int(b["Width"] ?? 0), Int(b["Height"] ?? 0), w[kCGWindowName as String] as? String ?? "")104}105
Files main
Menu

Theme