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