When you hide a window using setIsVisible(false) or orderOut(nil), it indeed removes the window from the list of visible windows returned by NSApp.windows. However, you can still access hidden windows by maintaining your own reference to them. Here's how you can modify your utility method to include both visible and hidden windows:
let windows = NSApp.windows
for window in windows {
if window.identifier == pWindowID {
return window
}
}
// If the window is not found among visible windows, try searching among hidden windows
let hiddenWindows = NSApp.windows.filter { !$0.isVisible }
for window in hiddenWindows {
if window.identifier == pWindowID {
return window
}
}
return nil
}
With this modification, the GetWindow function first checks if the window with the given identifier is among the visible windows. If not, it then searches among the hidden windows. This should allow you to find and access both visible and hidden windows using the same utility method.
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: