@@ -21,7 +21,7 @@ import AVFoundation
2121import ArgumentParser
2222import Cocoa
2323
24- let packageVersion = " 0.5 .1 "
24+ let packageVersion = " 0.6 .1 "
2525
2626var recorder : WindowRecorder ?
2727
@@ -41,6 +41,9 @@ struct RecordCommand: ParsableCommand {
4141 @Flag ( name: . shortAndLong, help: " List recordable windows. " )
4242 var list : Bool = false
4343
44+ @Flag ( name: . long, help: " Also include hidden windows when listing. " )
45+ var hidden : Bool = false
46+
4447 @Option (
4548 name: [ . customShort( " x " ) , . long] ,
4649 help: ArgumentHelp (
@@ -82,10 +85,15 @@ struct RecordCommand: ParsableCommand {
8285 }
8386
8487 if list {
85- NSWorkspace . shared. printWindowList ( )
88+ NSWorkspace . shared. printWindowList ( includeHidden : hidden )
8689 Darwin . exit ( 0 )
8790 }
8891
92+ if hidden {
93+ print ( " Error: can't use --hidden with anything other than --list " )
94+ Darwin . exit ( 1 )
95+ }
96+
8997 if let windowIdentifier = screenshot {
9098 if record != nil {
9199 print ( " Error: can't use --screenshot and --record simultaneously " )
@@ -217,8 +225,8 @@ struct WindowInfo {
217225}
218226
219227extension NSWorkspace {
220- func printWindowList( ) {
221- for window in allWindows ( ) {
228+ func printWindowList( includeHidden : Bool ) {
229+ for window in allWindows ( includeHidden : includeHidden ) {
222230 if window. title. isEmpty {
223231 print ( " \( window. identifier) \( window. app) " )
224232 } else {
@@ -228,15 +236,16 @@ extension NSWorkspace {
228236 }
229237
230238 func window( identifiedAs windowIdentifier: CGWindowID ) -> WindowInfo ? {
231- allWindows ( ) . first {
239+ allWindows ( includeHidden : true ) . first {
232240 $0. identifier == windowIdentifier
233241 }
234242 }
235243
236- func allWindows( ) -> [ WindowInfo ] {
244+ func allWindows( includeHidden : Bool ) -> [ WindowInfo ] {
237245 var windowInfos = [ WindowInfo] ( )
238246 let windows =
239- CGWindowListCopyWindowInfo ( . optionOnScreenOnly, kCGNullWindowID) as? [ [ String : Any ] ]
247+ CGWindowListCopyWindowInfo ( includeHidden ? . optionAll : . optionOnScreenOnly, kCGNullWindowID)
248+ as? [ [ String : Any ] ]
240249 for app in NSWorkspace . shared. runningApplications {
241250 for window in windows ?? [ ] {
242251 if let windowPid = window [ kCGWindowOwnerPID as String ] as? Int ,
@@ -507,7 +516,7 @@ func resolveWindowID(_ windowIdentifier: String) -> CGWindowID {
507516 if let identifier = CGWindowID ( windowIdentifier) {
508517 return identifier
509518 }
510- if let window = NSWorkspace . shared. allWindows ( ) . filter ( {
519+ if let window = NSWorkspace . shared. allWindows ( includeHidden : true ) . filter ( {
511520 $0. app. trimmingCharacters ( in: . whitespacesAndNewlines)
512521 . caseInsensitiveCompare ( windowIdentifier. trimmingCharacters ( in: . whitespacesAndNewlines) )
513522 == . orderedSame
0 commit comments