macOS command line utility to retrieve the CGWindowID of the specified window (useful for screencapture).
Via Homebrew:
brew install gsbabil/getwindowid/getwindowid ./GetWindowID <application-bundle-name> <window-title>For example, to get the ID of the iOS/tvOS/watchOS Simulator:
./GetWindowID Simulator 'iPhone X - iOS 11.0'…and to capture a screenshot of it:
screencapture -l$(./GetWindowID Simulator 'iPhone X - iOS 11.0') simulator.pngTo get the ID of a window without a title, pass an empty string as the title:
./GetWindowID GLFW ''To list all of an app's windows, pass --list as the title:
./GetWindowID Simulator --list-
Terminal.appandsshd-keygen-wrappermust be added and enabled in the following system settings. Otherwise, the "title" information of the apps will appear as "(null)" due to MacOS's privacy and security features.MacOS Settings.app > Privacy & Security > Accessibility > Allow the applications below to control your computer.