Skip to content

Instantly share code, notes, and snippets.

@Jaycedam
Last active November 16, 2025 14:16
Show Gist options
  • Select an option

  • Save Jaycedam/4db80fc49c1d23c76c90c9b3e653c07f to your computer and use it in GitHub Desktop.

Select an option

Save Jaycedam/4db80fc49c1d23c76c90c9b3e653c07f to your computer and use it in GitHub Desktop.
Install Kanata and latest Karabiner driver on macOS
#!/usr/bin/env bash
# Installs Karabiner DriverKit, Kanata, and sets up LaunchDaemons (no disk logging)
set -euo pipefail
# Color variables
MAGENTA='\033[35m'
RESET='\033[0m'
ARROW="${MAGENTA}==>${RESET}"
#### CONFIGURATION ####
KANATA_CONFIG="${HOME}/.config/kanata/config.kbd"
KANATA_PORT=10000
PLIST_DIR="/Library/LaunchDaemons"
###################################
# 1. Fetch & install latest Karabiner DriverKit pkg
echo "Fetching latest Karabiner DriverKit pkg URL..."
DRIVERKIT_PKG_URL=$(
curl -s "https://api.github.com/repos/pqrs-org/Karabiner-DriverKit-VirtualHIDDevice/releases/latest" |
jq -r '.assets[] | select(.name|endswith(".pkg")) | .browser_download_url'
)
echo "Downloading DriverKit from: $DRIVERKIT_PKG_URL"
curl -L -o /tmp/karabiner-driverkit.pkg "$DRIVERKIT_PKG_URL"
echo "Installing DriverKit..."
sudo installer -pkg /tmp/karabiner-driverkit.pkg -target /
rm -f /tmp/karabiner-driverkit.pkg
# 2. Install Kanata via Homebrew if not present
brew list kanata >/dev/null 2>&1 || brew install kanata
KANATA_BIN=$(command -v kanata)
# 3. Write plist files
sudo tee "${PLIST_DIR}/com.example.kanata.plist" >/dev/null <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>com.example.kanata</string>
<key>ProgramArguments</key><array>
<string>${KANATA_BIN}</string>
<string>-c</string><string>${KANATA_CONFIG}</string>
<string>--port</string><string>${KANATA_PORT}</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
</dict></plist>
EOF
sudo chown root:wheel "${PLIST_DIR}/com.example.kanata.plist"
sudo chmod 644 "${PLIST_DIR}/com.example.kanata.plist"
sudo tee "${PLIST_DIR}/com.example.karabiner-vhiddaemon.plist" >/dev/null <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>com.example.karabiner-vhiddaemon</string>
<key>ProgramArguments</key><array>
<string>/Library/Application Support/org.pqrs/Karabiner-DriverKit-VirtualHIDDevice/Applications/Karabiner-VirtualHIDDevice-Daemon.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Daemon</string>
</array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
</dict></plist>
EOF
sudo chown root:wheel "${PLIST_DIR}/com.example.karabiner-vhiddaemon.plist"
sudo chmod 644 "${PLIST_DIR}/com.example.karabiner-vhiddaemon.plist"
sudo tee "${PLIST_DIR}/com.example.karabiner-vhidmanager.plist" >/dev/null <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>com.example.karabiner-vhidmanager</string>
<key>ProgramArguments</key><array>
<string>/Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager</string>
<string>activate</string>
</array>
<key>RunAtLoad</key><true/>
</dict></plist>
EOF
sudo chown root:wheel "${PLIST_DIR}/com.example.karabiner-vhidmanager.plist"
sudo chmod 644 "${PLIST_DIR}/com.example.karabiner-vhidmanager.plist"
# 4. Bootstrap and enable services
# Kanata
sudo launchctl bootout system "${PLIST_DIR}/com.example.kanata.plist" 2>/dev/null || true
sudo launchctl bootstrap system "${PLIST_DIR}/com.example.kanata.plist"
sudo launchctl enable system/com.example.kanata
# Karabiner-VHIDDaemon
sudo launchctl bootout system "${PLIST_DIR}/com.example.karabiner-vhiddaemon.plist" 2>/dev/null || true
sudo launchctl bootstrap system "${PLIST_DIR}/com.example.karabiner-vhiddaemon.plist"
sudo launchctl enable system/com.example.karabiner-vhiddaemon
# Karabiner-VHIDManager
sudo launchctl bootout system "${PLIST_DIR}/com.example.karabiner-vhidmanager.plist" 2>/dev/null || true
sudo launchctl bootstrap system "${PLIST_DIR}/com.example.karabiner-vhidmanager.plist"
sudo launchctl enable system/com.example.karabiner-vhidmanager
# 5. Prompt for permissions
echo -e "${ARROW} You'll now allow Karabiner to use a system extension."
echo -e "On the next screen, approve the extension when prompted."
read -rp "Press Enter to open System Extensions..."
open "x-apple.systempreferences:com.apple.LoginItems-Settings.extension"
echo
read -rp "Press Enter once you're done..."
echo
echo -e "${ARROW} You'll now add Kanata to Accessibility settings."
echo -e "On the next screen:"
echo -e "- Click '+' to add a new item"
echo -e "- Press Shift+Command+G and enter ${MAGENTA}/opt/homebrew/bin${RESET}"
echo -e "- Select the Kanata binary"
read -rp "Press Enter to open Accessibility settings..."
open "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
echo
read -rp "Press Enter once you're done..."
echo
echo -e "${ARROW} Now add Kanata to Input Monitoring as well."
echo -e "Follow the same steps as before."
read -rp "Press Enter to open Input Monitoring settings..."
open "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent"
echo
read -rp "Press Enter once you're done..."
echo
echo "Kanata and Karabiner services are now installed and enabled."
@InSasquatchCountry
Copy link

InSasquatchCountry commented Oct 20, 2025

I ran the script but it does't seem to run on startup :/

╰─$ kanata -h   
kanata: an advanced software key remapper

Usage: 

Options:
  -c, --cfg <CFG>               Configuration file(s) to use with kanata. If not specified, defaults to
                                kanata.kbd in the current working directory and
                                '$HOME/Library/Application Support/kanata/kanata.kbd'.
...

I hadn't looked closely at KANATA_CONFIG="${HOME}/.config/kanata/config.kbd"

worked great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment