Last active
January 2, 2021 22:28
-
-
Save atduskgreg/5815506 to your computer and use it in GitHub Desktop.
A utility for printing out the name and windowId for every current window. Use in conjunction with 'screencapture -l' to automate screenshots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetWindowList | |
// A utility for printing out the name and windowId for every current window. | |
// Use in conjunction with 'screencapture -l' to automate screenshots. | |
// compile with gcc thusly: | |
// gcc -framework carbon -framework foundation -framework cocoa -x objective-c -std=c99 GetWindowList.c -o GetWindowList | |
#include <Carbon/Carbon.h> | |
#import <objc/Object.h> | |
#import <Foundation/Foundation.h> | |
#import <Cocoa/Cocoa.h> | |
int main(int argc, char **argv) { | |
CFArrayRef windowArray = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); | |
NSMutableArray *windowsInMap = [NSMutableArray arrayWithCapacity:64]; | |
NSArray* windows = (NSArray*)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); | |
NSUInteger count = [windows count]; | |
for (NSUInteger i = 0; i < count; i++) | |
{ | |
NSDictionary* nswindowsdescription = [windows objectAtIndex:i]; | |
NSNumber* windowid = (NSNumber*)[nswindowsdescription objectForKey:@"kCGWindowNumber"]; | |
NSString* windowName = (NSString*)[nswindowsdescription objectForKey:@"kCGWindowOwnerName"]; | |
if(windowid) | |
{ | |
printf("%s:%s\n", [windowName UTF8String], [[windowid stringValue] UTF8String]); | |
} | |
} | |
CFRelease(windowArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment