I would like to change the input source (keyboard layout) from within my AOSC script. I found TISSelectInputSource as possible option in http://macscripter.net/viewtopic.php?id=26894 but my first attempt in translating this to ASOC failed miserably.
set inputSource to “German”
current application’s TISSelectInputSource_(inputSource)
As usual I would appreciate any help to get this working in ASOC.
The bad news is, TISSelectInputSource is a C function which cannot be exposed to AppleScriptObjC.
But even if it was possible, inputSource is not a string it’s a C reference type.
In C / Objective-C the code to be able to change the language is something like this
it gets all available languages and puts them into a Dictionary with their localized names as keys. Then it grabs the German source reference and sets the language.
However this code is usable in AppleScriptObjC with a bridge class
¢ In Xcode create a new OS X Cocoa Class, Language Objective-C Subclass of NSObject and name it InputSwitcher
¢ Replace the contents of InputSwitcher.h with
[code]@import Foundation;
@interface InputSwitcher : NSObject
(BOOL)setLanguage:(NSString *)language;
@end[/code]
¢ Replace the contents of InputSwitcher.m with