Hi magic people
I'm currently finishing up a project and making sure everything runs smooth whether sighted or voice over user, and am coming across a snag.
I'm trying to observe a key in CFPreferences which tells whether the trackpad commander is on or off. I need this in order to have the trackpad turn a few things off when it's on and back on when it turns off.
I so far have a key I know which is to check whether voice over is on as below:
let VOFlag:Bool = {
let flag = CFPreferencesCopyValue("voiceOverOnOffKey" as CFString, "com.apple.universalaccess" as CFString, NSUserName() as CFString, Host.current().localizedName! as CFString)
return ((flag as! Int) == 1) ? true : false
}()
However, I have 2 questions: 1-Which is the key for checking if trackpad commander is on or off? I tried going to ~/Library/Preferences/ but there are many files and a grep may help but perhaps someone here already has the key? :) 2-Is there a way to observe said key and have a callback function associated to it?
I feel I'm close to finding the solution myself, but if someone can cut through the chase with an answer, I got a virtual bean of the month cappuccino for you haha
Update:
By looking into ~/Library/Preferences and doing a grep, I found SCRCTrackpadCommanderEnabled
So i guess the above code can become: let flag = CFPreferencesCopyValue("SCRCTrackpadCommanderEnabled" as CFString, "com.apple.universalaccess" as CFString, NSUserName() as CFString, Host.current().localizedName! as CFString)
But now how do I observe this key? The value I get is a CFPropertyList? and I'm copying the value in the above. I couldn't find a CFPreferencesObserve or other type of functions.
Edit 2:
i tried the following:
flag!.addObserver(self, selector: #selector(testVO), name: nil, object: nil)
@objc func testVO() { print("toggled") }
but I get: __NSCFBoolean addObserver:selector:name:object:]: unrecognized selector sent to instance