Created
January 26, 2018 07:03
-
-
Save zhanggang807/e3a9683a833b56442ae722150b916452 to your computer and use it in GitHub Desktop.
im-select:change mac input method via command line. copied from https://github.com/CodeFalling/smart-im-osx
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
// | |
// im-select | |
// | |
// Created by Ying Bian on 8/21/12. | |
// Copyright (c) 2012 Ying Bian. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <Carbon/Carbon.h> | |
int main(int argc, const char * argv[]) { | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
int returnCode = 0; | |
if (argc > 1) { | |
NSString *imId = [NSString stringWithUTF8String:argv[1]]; | |
NSDictionary *filter = [NSDictionary dictionaryWithObject:imId forKey:(NSString *)kTISPropertyInputSourceID]; | |
CFArrayRef keyboards = TISCreateInputSourceList((CFDictionaryRef)filter, false); | |
if (keyboards) { | |
TISInputSourceRef selected = (TISInputSourceRef)CFArrayGetValueAtIndex(keyboards, 0); | |
returnCode = TISSelectInputSource(selected); | |
CFRelease(keyboards); | |
} else { | |
returnCode = 1; | |
} | |
} else { | |
TISInputSourceRef current = TISCopyCurrentKeyboardInputSource(); | |
NSString *sourceId = (NSString *)(TISGetInputSourceProperty(current, kTISPropertyInputSourceID)); | |
fprintf(stdout, "%s\n", [sourceId UTF8String]); | |
CFRelease(current); | |
} | |
[pool release]; | |
return returnCode; | |
} |
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
CC=/usr/bin/clang | |
NAME=im-select | |
INSTALL_PATH=/usr/local/bin/ | |
OPTS=-framework foundation -framework carbon | |
all: | |
$(CC) $(OPTS) -o $(NAME) $(NAME).m | |
install:$(NAME) | |
cp $(NAME) $(INSTALL_PATH) | |
uninstall: | |
rm $(INSTALL_PATH)$(NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment