Skip to content

Instantly share code, notes, and snippets.

@xhruso00
Forked from lukhnos/gist:2892699
Created October 9, 2017 16:08
Show Gist options
  • Save xhruso00/cf8243b552be4fb5372c857e602f6859 to your computer and use it in GitHub Desktop.
Save xhruso00/cf8243b552be4fb5372c857e602f6859 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