I am trying to convert *const __CFData to String in rust.
I am trying to get Keyboard language and checking if it is a particular language.
let current_source = ffi::TISCopyCurrentKeyboardLayoutInputSource();
let current_language = ffi::TISGetInputSourceProperty(current_source, ffi::kTISPropertyLocalizedName);
let language = CFDataGetBytePtr(current_language);
CStr::from_ptr(language).to_str().unwrap().to_string().contains("English")
I get this runtime error - -[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x7ff85dfed1d8
TISGetInputSourceProperty returns a *const __CFData and CFDataGetBytePtr should return a *const u8, but it fails at that function with the mentioned error.
How do I get the language and check what it is in rust? TIA.
So I played around with this a little, and came up with the following, which seems to work. Note that, as far as I could tell, this API is definitely deprecated though.
(the following needs
libcas a dependency)Note that
CFStringGetCStringPtrdid not work for me, as it returned a null-pointer. I'm guessing this is because (docs):