-
-
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
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
// 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