-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathim-select.m
37 lines (31 loc) · 1.17 KB
/
im-select.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// 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;
}