Skip to content

Instantly share code, notes, and snippets.

@informationsea
Created May 20, 2020 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save informationsea/19137be76200b3ac2750b2f4a0ab3f73 to your computer and use it in GitHub Desktop.
Save informationsea/19137be76200b3ac2750b2f4a0ab3f73 to your computer and use it in GitHub Desktop.
macOS input method change tool
#include <stdio.h>
#include <string.h>
#include <Carbon/Carbon.h>
int main(int nargs, char** argv) {
if (nargs != 2) {
fprintf(stderr, "%s (on|off)\n", argv[0]);
return 1;
}
TISInputSourceRef is = NULL;
if (strcmp(argv[1], "on") == 0) {
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
is = TISCopyInputSourceForLanguage(locale);
} else if (strcmp(argv[1], "off") == 0) {
is = TISCopyCurrentASCIICapableKeyboardInputSource();
} else {
fprintf(stderr, "%s (on|off)\n", argv[0]);
return 1;
}
if (is) TISSelectInputSource(is);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment