Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macOSでIME(日本語入力)の情報を取得する
#!/usr/bin/swift
import Carbon
// Carbon.h -> HIToolbox.h -> TextInputSources.h
// grep "extern const" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/TextInputSources.h
let props: [CFString] = [
kTISPropertyInputSourceCategory,
kTISPropertyInputSourceType,
kTISPropertyInputSourceIsASCIICapable,
kTISPropertyInputSourceIsEnableCapable,
kTISPropertyInputSourceIsSelectCapable,
kTISPropertyInputSourceIsEnabled,
kTISPropertyInputSourceIsSelected,
kTISPropertyInputSourceID,
kTISPropertyBundleID,
kTISPropertyInputModeID,
kTISPropertyLocalizedName,
kTISPropertyInputSourceLanguages,
kTISPropertyUnicodeKeyLayoutData,
kTISPropertyIconRef,
kTISPropertyIconImageURL,
kTISCategoryKeyboardInputSource,
kTISCategoryPaletteInputSource,
kTISCategoryInkInputSource,
kTISTypeKeyboardLayout,
kTISTypeKeyboardInputMethodWithoutModes,
kTISTypeKeyboardInputMethodModeEnabled,
kTISTypeKeyboardInputMode,
kTISTypeCharacterPalette,
kTISTypeKeyboardViewer,
kTISTypeInk,
kTISNotifySelectedKeyboardInputSourceChanged,
kTISNotifyEnabledKeyboardInputSourcesChanged
]
let inputSourceRef = TISCopyCurrentKeyboardInputSource().takeUnretainedValue()
for p in props {
if let v = TISGetInputSourceProperty(inputSourceRef, p) {
let v2 = Unmanaged<AnyObject>.fromOpaque(v).takeUnretainedValue()
print(p, v2)
}
}
TISPropertyInputSourceCategory TISCategoryKeyboardInputSource
TISPropertyInputSourceType TISTypeKeyboardInputMode
TISPropertyInputSourceIsASCIICapable 1
TISPropertyInputSourceIsEnableCapable 1
TISPropertyInputSourceIsSelectCapable 1
TSMInputSourcePropertyIsEnabled 1
TSMInputSourcePropertyIsSelected 1
TISPropertyInputSourceID com.google.inputmethod.Japanese.Roman
TSMInputSourcePropertyBundleID com.google.inputmethod.Japanese
TSMInputSourcePropertyInputMode com.apple.inputmethod.Roman
TSMInputSourcePropertyLocalizedName Alphanumeric (Google)
TISPropertyInputSourceLanguages (
en
)
TISPropertyIconImageURL Contents/Resources/direct.tiff -- file:///Library/Input%20Methods/GoogleJapaneseInput.app/
TISPropertyInputSourceCategory TISCategoryKeyboardInputSource
TISPropertyInputSourceType TISTypeKeyboardInputMode
TISPropertyInputSourceIsASCIICapable 0
TISPropertyInputSourceIsEnableCapable 1
TISPropertyInputSourceIsSelectCapable 1
TSMInputSourcePropertyIsEnabled 1
TSMInputSourcePropertyIsSelected 1
TISPropertyInputSourceID com.google.inputmethod.Japanese.base
TSMInputSourcePropertyBundleID com.google.inputmethod.Japanese
TSMInputSourcePropertyInputMode com.apple.inputmethod.Japanese
TSMInputSourcePropertyLocalizedName Hiragana (Google)
TISPropertyInputSourceLanguages (
ja
)
TISPropertyIconImageURL Contents/Resources/hiragana.tiff -- file:///Library/Input%20Methods/GoogleJapaneseInput.app/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment