Created
May 13, 2017 10:44
-
-
Save aronskaya/efc58a4074f3f61eaa2d9e3b607d92dc to your computer and use it in GitHub Desktop.
[TISInputSource+Extensions] #tags: inputSource
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
extension TISInputSource { | |
var id: String { | |
let unsafeID = TISGetInputSourceProperty(self, kTISPropertyInputSourceID).assumingMemoryBound(to: CFString.self) | |
let name = Unmanaged<CFString>.fromOpaque(unsafeID).takeUnretainedValue() | |
return name as String | |
} | |
var type: String { | |
let unsafeID = TISGetInputSourceProperty(self, kTISPropertyInputSourceType).assumingMemoryBound(to: CFString.self) | |
let name = Unmanaged<CFString>.fromOpaque(unsafeID).takeUnretainedValue() | |
return name as String | |
} | |
var isEnabled: Bool { | |
let unsafeIsEnabled = TISGetInputSourceProperty(self, kTISPropertyInputSourceIsEnabled).assumingMemoryBound(to: CFBoolean.self) | |
let isEnabled = CFBooleanGetValue(Unmanaged<CFBoolean>.fromOpaque(unsafeIsEnabled).takeUnretainedValue()) | |
return isEnabled | |
} | |
var isSelected: Bool { | |
let unsafeIsSelected = TISGetInputSourceProperty(self, kTISPropertyInputSourceIsSelected).assumingMemoryBound(to: CFBoolean.self) | |
let isSelected = CFBooleanGetValue(Unmanaged<CFBoolean>.fromOpaque(unsafeIsSelected).takeUnretainedValue()) | |
return isSelected | |
} | |
var isEnableCapable: Bool { | |
let unsafeIsEnableCapable = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceIsEnableCapable).assumingMemoryBound(to: CFBoolean.self) | |
let isEnableCapable = CFBooleanGetValue(Unmanaged<CFBoolean>.fromOpaque(unsafeIsEnableCapable).takeUnretainedValue()) | |
return isEnableCapable | |
} | |
var isSelectCapable: Bool { | |
let unsafeIsSelectCapable = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceIsSelectCapable).assumingMemoryBound(to: CFBoolean.self) | |
let isSelectCapable = CFBooleanGetValue(Unmanaged<CFBoolean>.fromOpaque(unsafeIsSelectCapable).takeUnretainedValue()) | |
return isSelectCapable | |
} | |
func enable() { | |
if TISEnableInputSource(self) != noErr { | |
print("Input source enabling falied. Source: \(self)") | |
} | |
} | |
func disable() { | |
if TISDisableInputSource(self) != noErr { | |
print("Input source disabling falied. Source: \(self)") | |
} | |
} | |
func select() { | |
if TISSelectInputSource(self) != noErr { | |
print("input selection failed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment