OSX - Automatically change input source for different keyboards
When pluggning an external keyboard on OSX, a wizard pops up to help select the keyboard layout. That layout is then somehow saved and reused automatically when you plug the external keyboard at a later point.
Additionnaly if you use the keyboard viewer you can see the keyboard layout change in real time based on which keyboard's key was last pressed.
I am trying to find a way to achieve the same effect for the input source. Basically a way to register an input source with a specific keyboard and have the input source switch back and forth automatically when pressing a key from one keyboard or another.
I do pair programming often and would like to have my pair use her/his keyboard with the proper layout and mapping while I use the internal keyboard on my mac book pro.
I know I can add a "shortcut" to switch input source but that adds an uncanny step when one of the pair wants to intervene in the code. (not to mention that we usually also have to change the IDE keymap which makes it even slower and more awkward).
If you are unaware of a tool to do this but have pointers to resources on how to build one I would also be interested as I have a hard time finding documentation on OSX events.
Solution 1:
-- EDIT 01/2022 --
Ole Hüter has forked the original repository and fixed the build for newer versions of OSX. You can get a working autokbisw from his fork.
-- EDIT 12/2020 --
I no longer maintain autokbisw since I don't own a mac laptop anymore, I am willing to give access or transfer whatever needs transferring if anyone is up for it, ping me on github. (Also such a tool doesn't seem to exist for linux either, I'm going to have to read up on these APIS \o/)
Since I was unable to find any existing way to do this, I created autokbisw.
autokbisw (automatic keyboard input source switcher) will remember the last chosen input source for each keyboard it 'sees' and restore the corresponding input source every time the keyboard becomes active. The "active" keyboard is the last keyboard to send an input event. Whenever the input source changes externally, it will update the input source for the active keyboard.
This way the input source behaves as if the input source selector was specific to a keyboard and not to the system. Same as the keyboard layout.
Solution 2:
autokbisw works wonderfully !!
Simply brew install it, enable service, and keyboard switching is now automatic !!
brew install jeantil/autokbisw/autokbisw
brew services start jeantil/autokbisw/autokbisw