Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Created June 8, 2012 00:45
Show Gist options
  • Save lukhnos/2892699 to your computer and use it in GitHub Desktop.
Save lukhnos/2892699 to your computer and use it in GitHub Desktop.
Enumerate all available keyboard layouts on Mac OS X and write out their icons
// need to include <Carbon/Carbon.h> and link against Carbon.framework
// not every layout/input method has TIFF icon
CFArrayRef list = TISCreateInputSourceList(NULL, true);
for (int i = 0; i < CFArrayGetCount(list); i++) {
TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(list, i);
IconRef icon = TISGetInputSourceProperty(source, kTISPropertyIconRef);
CFStringRef sourceID = TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
NSString *path = [[@"/tmp/" stringByAppendingPathComponent:(id)sourceID] stringByAppendingPathExtension:@"tiff"];
[[[[[NSImage alloc] initWithIconRef:icon] autorelease] TIFFRepresentation] writeToFile:path atomically:YES];
CFRelease(sourceID);
ReleaseIconRef(icon);
}
CFRelease(list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment