Created
October 6, 2015 15:47
-
-
Save danielpunkass/6b233131fdda4b9cbe7e to your computer and use it in GitHub Desktop.
Simple tool to change the selected input source to named keyboard...
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
// | |
// main.m | |
// ChangeKeyboard | |
// | |
// Created by Daniel Jalkut on 10/6/15. | |
// Copyright © 2015 Red Sweater. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <Carbon/Carbon.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
if (argc < 2) | |
{ | |
NSLog(@"Usage: %s <language>", argv[0]); | |
} | |
else | |
{ | |
NSString* targetLanguage = [NSString stringWithUTF8String:argv[1]]; | |
TISInputSourceRef targetInputSource = NULL; | |
for (id thisInputSource in (NSArray*)TISCreateInputSourceList(NULL, 0)) | |
{ | |
NSString* thisSourceName = (NSString*)TISGetInputSourceProperty((TISInputSourceRef)thisInputSource, kTISPropertyLocalizedName); | |
if ([thisSourceName isEqualToString:targetLanguage]) | |
{ | |
targetInputSource = (TISInputSourceRef)thisInputSource; | |
break; | |
} | |
} | |
if (targetInputSource == NULL) | |
{ | |
NSLog(@"Error: Could not find enabled input source matching language name: %@", targetLanguage); | |
} | |
else | |
{ | |
TISSelectInputSource(targetInputSource); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment