Skip to content

Instantly share code, notes, and snippets.

@informationsea
Created April 12, 2024 06:31
Show Gist options
  • Save informationsea/5d9adf88632f3ad61923f585ce46febf to your computer and use it in GitHub Desktop.
Save informationsea/5d9adf88632f3ad61923f585ce46febf to your computer and use it in GitHub Desktop.
Switch Input method on macOS
#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