Automatic keyboard/input source switching for OSX

Last update: May 20, 2022

Autokbisw - Automatic keyboard input source switcher

Motivation

This small utility was born out of frustation after a mob programming sesssion. The session took place on a french mac book pro, using a pair of french pc keyboards. Some programmers were used to eclipse, others to intellij on linux, others to intellij on mac.

While macOS automatically switches the layout when a keyboard is activated it doesn't change the keymap, meaning we had to remember changing both the OS and the IDE keymap each time we switched developer.

This software removes one of the switches: it memorizes the last active macOS input source for a given keyboard and restores it automatically when that keyboard becomes the active keyboard.

Homebrew

Install as a service using Homebrew:

brew install ohueter/tap/autokbisw
brew services start ohueter/tap/autokbisw

autokbisw needs privileges to monitor all keyboard input. You have to grant these privileges on the first start of the service.

Throubleshooting

If autokbisw doesn't work after the first start of the service, try to restart it:

brew services restart ohueter/tap/autokbisw

If autokbisw still doesn't work even after rebooting, try re-adding the executable manually to System Preferences > Security & Privacy > Privacy > Input Monitoring (after removing existing entries). The path to add should be /usr/local/bin/autokbisw (Intel Macs) or /opt/homebrew/opt/autokbisw/bin/autokbisw (Apple M1 Macs).

Building from source

Clone this repository, make sure you have XCode installed and run the following commands:

cd autokbisw
swift build --configuration release

In the output will be the path to the built program, something like .build/release/autokbisw.

You can run it from the release directory as is.

Installation

To install it in /usr/local/bin, run:

sudo cp .build/release/autokbisw /usr/local/bin/

If you want the program to start automatically when you log in, you can copy the provided plist file to ~/Library/LaunchAgents and load it manually for the first run:

cp eu.byjean.autokbisw.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/eu.byjean.autokbisw.plist

Troubleshooting

If launchctl returns an error, you may try one of the following:

1. Reboot

Running launchctl sometimes produced inexplainable error messages (to me), that often were gone after rebooting. 🤷‍♂️

2. Unload and load the service again:

launchctl unload ~/Library/LaunchAgents/eu.byjean.autokbisw.plist
launchctl load ~/Library/LaunchAgents/eu.byjean.autokbisw.plist

3. Force a restart of the service:

launchctl kickstart -kp gui/501/eu.byjean.autokbisw

This may be needed on the first run, after permissions to capture all keyboard events have been granted.

501 may need to be replaced with your user id (uid). To find your user id, run:

id

4. Maybe you need to (re-)enable the service:

launchctl enable gui/501/eu.byjean.autokbisw

Acknowledgements

This program has originally been developed by Jean Helou (@jeantil).

GitHub

https://github.com/ohueter/autokbisw
You might also like...

Best way to dismiss Keyboard in a View Controller iOS (Swift)

Best way to dismiss Keyboard in a View Controller iOS (Swift)

Best way to dismiss Keyboard in a View Controller iOS (Swift) First way: Implement UITextFieldDelegate’s textFieldShouldReturn method and dismiss curr

Dec 18, 2021

Showing / dismissing keyboard animation in simple UIViewController category.

Showing / dismissing keyboard animation in simple UIViewController category.

RSKKeyboardAnimationObserver Easy way to handle iOS keyboard showing/dismissing. Introduction Working with iOS keyboard demands a lot of duplicated co

Jun 24, 2021

Objective-C library for tracking keyboard in iOS apps.

Objective-C library for tracking keyboard in iOS apps.

NgKeyboardTracker Objective-c library for tracking keyboard in iOS apps. Adding to your project If you are using CocoaPods, add to your Podfile: pod '

Feb 2, 2022

A simple keyboard to use with numbers and, optionally, a decimal point.

A simple keyboard to use with numbers and, optionally, a decimal point.

MMNumberKeyboard A simple keyboard to use with numbers and, optionally, a decimal point. Installation From CocoaPods CocoaPods is a dependency manager

May 16, 2022

For less complicated keyboard event handling.

KeyboardObserver For less complicated keyboard event handling. Features Less complicated keyboard event handling. Do not use Notification , but event

May 11, 2022

A drop-in universal solution for moving text fields out of the way of the keyboard in iOS

TPKeyboardAvoiding A drop-in universal solution for moving text fields out of the way of the keyboard in iOS. Introduction There are a hundred and one

May 11, 2022

KeyboardMan helps you to make keyboard animation.

KeyboardMan We may need keyboard infomation from keyboard notifications to do animation. However, the approach is complicated and easy to make mistake

Apr 19, 2022

Emoji Keyboard SDK (iOS)

Emoji Keyboard SDK (iOS)

Makemoji SDK Makemoji is a free emoji keyboard for mobile apps. By installing our keyboard SDK every user of your app will instantly have access to ne

Apr 29, 2022

A Chinese keyboard for iOS that helps Chinese language learners remember tones.

A Chinese keyboard for iOS that helps Chinese language learners remember tones.

ToneBoard ToneBoard is a Chinese keyboard for iOS that requires you to enter the correct tones while typing simplified Chinese with Pinyin. It is avai

Apr 18, 2022
Comments
  • 1. Added a check to prevent switching if the device is a mouse

    Thanks for updating this useful tool to work on the latest OSX! My new Logitech mouse reports as a keyboard so it would cause unintended language switching whenever I moved it (same problem as this issue https://github.com/jeantil/autokbisw/issues/18 in the older version). This check to see if it conforms to mouse solves the issue with my setup at least.

    Reviewed by ryanmccardle at 2022-04-22 12:00
Related tags
SwiftUIKeyPress - a package to make up for the lack of keyboard input in SwiftUI
SwiftUIKeyPress - a package to make up for the lack of keyboard input in SwiftUI

SwiftUIKeyPress - a package to make up for the lack of keyboard input in SwiftUI

Apr 15, 2022
Slidden is an open source, customizable, iOS 8 keyboard, written in Swift
Slidden is an open source, customizable, iOS 8 keyboard, written in Swift

Slidden is an open source, customizable, iOS 8 keyboard, written in Swift. iOS 8 brought us the ability to create fully customizable keyboards, but do

Mar 1, 2022
IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!
IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!

IHKeyboardAvoiding An elegant solution for keeping any UIView visible when the keyboard is being shown Requirements IHKeyboardAvoiding Version Objecti

May 2, 2022
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

IQKeyboardManager While developing iOS apps, we often run into issues where the iPhone keyboard slides up and covers the UITextField/UITextView. IQKey

May 16, 2022
Codeless manager to hide keyboard by tapping on views for iOS written in Swift
Codeless manager to hide keyboard by tapping on views for iOS written in Swift

KeyboardHideManager KeyboardHideManager - codeless manager to hide keyboard by tapping on views for iOS written in Swift. Structure Features Requireme

Jan 29, 2022
⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes
⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes

This package lets you add support for user-customizable global keyboard shortcuts to your macOS app in minutes. It's fully sandbox and Mac App Store c

May 21, 2022
Swift UIKit keyboard manager for iOS apps.

Typist Typist is a small, drop-in Swift UIKit keyboard manager for iOS apps. It helps you manage keyboard's screen presence and behavior without notif

May 12, 2022
Suppress mouse & keyboard events on MacOSX. Baby-proof my Mac!

Suppress mouse & keyboard events on MacOSX Catches all events (mouse, keyboard, everything), and either consumes them (locked state) or passes them th

Jun 5, 2021
KeyboardKit is a Swift library that helps you create custom keyboard extensions for iOS and ipadOS.
KeyboardKit is a Swift library that helps you create custom keyboard extensions for iOS and ipadOS.

KeyboardKit is a Swift library that helps you create custom keyboard extensions for iOS and ipadOS.

May 22, 2022
QMK Agent is a macOS menubar application which sends commands to a QMK enabled keyboard
QMK Agent is a macOS menubar application which sends commands to a QMK enabled keyboard

QMKagent QMK Agent is a macOS menubar application which sends commands to a QMK enabled keyboard Features System volume indicator using top row (Esc t

Apr 24, 2022