OSX - Automatically change input source for different keyboards
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 ohueter/tap/autokbisw
brew services start ohueter/tap/autokbisw
Related videos on Youtube
Jean
Jean is a professional developer since 2004, passionate and curious, he doesn't stop when he gets home, simply changing technologies :) While his professional career is in the java/j2ee space, his hobbyist career lead him into ruby and rails, and more recently back to the jvm with scala, playframework and functionnal programming. He has mastered multiple scm (CVS, SVN, GIT, and others he his ashamed of mentionning) and IDEs ( Eclipse, Intellij), he has worked on traditionnal web applications, on message based applications. Mostly imperative languages but more and more functional ones, synchronous or asynchronous processing. Jean also loves to share knowledge and seeks to learn ever more.
Updated on September 18, 2022Comments
-
Jean over 1 year
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.
-
Pengő Dzsó over 7 yearsLove this! And works on Sierra as well!
-
Jean over 7 yearsglad you like it :)
-
Kai Engelhardt almost 7 yearsThis tool is awesome. Today I got a US keyboard for my German MacBook and this is exactly what I was looking for. Great job!
-
Tran Quan over 6 yearsit's so cool man
-
Jean almost 5 yearsI'm glad you like it :)
-
Gaetan almost 5 yearsyes it is actually amazing :) I see thqt only the first stroke is wrong, and the layout is switched just after that. I guess this is not something you can anything. But frankly, thanks for this tool :)
-
Jean almost 5 yearsThe layout is changed when the first input event from the other keyboard is received. autokbisw doesn't intercept events (that would require way more code ) it only listens to the events. But that means the layout changes after that first key press. I usually press control or alt or any key that doesn't actually do anything to trigger the switch then start typing....
-
Jean almost 5 yearsIntercepting the event to translate it and reemit in the new layout would require a kernel extension. It's way more invasive and difficult to maintain... Karabiner does it though if you can't live without it ;)
-
Gaetan almost 5 yearsthe "press ctl first" solution is good enough. Thanks again !
-
FeliceM about 4 yearsBeautiful solutions. Has anyone tested this with Catalina?
-
Admin almost 2 years@Jean In a terminal, I ran the latest binary downloaded from the fork. On another window, I typed from both my keyboards but it didn't change? I am running the latest MacOS Momnterey 12.4. Could you please suggest if I need to do anything. I gave terminal the rights to monitor, when the binary prompted me to do so.
-
Admin almost 2 years@Jean Also, is there any ways to contact Ole Hüter?
-
Admin almost 2 years@porcupine, I don't have a specific/priviledged mean to contact Ole Hüter. Note that autokbisw does not guess the correct input source for your keyboard, it only remembers the last input source selected when a given keyboard was active and restores it when that keyboard becomes active again