Skip to content

Instantly share code, notes, and snippets.

@hotpocket
Last active October 9, 2025 21:38
Show Gist options
  • Save hotpocket/e8ae87fb84bc34d9989beb1df9bf51fd to your computer and use it in GitHub Desktop.
Save hotpocket/e8ae87fb84bc34d9989beb1df9bf51fd to your computer and use it in GitHub Desktop.
keychron enable / disable bash function so it can be modified via keychron's web UI
# this creates a (ba)sh function, so if you want to use it source it in your shell.
# Or copy it into it for a one time use
# enable/disable keychron keyboard to be editable from the web UI
# e.g. Don't trust the web UI to modify my keyboard by default
keychronctl() {
local action=$1
echo "🔍 Scanning Keychron devices (excluding 'Link' interfaces)..."
# Collect only Keychron non-Link devices
mapfile -t devices < <(
for i in /dev/hidraw*; do
if udevadm info -a -n "$i" | grep -q "Keychron"; then
local product
product=$(udevadm info -a -n "$i" | grep 'ATTRS{product}' | head -1 | awk -F'==' '{print $2}' | tr -d '"')
if [[ ! "$product" =~ [Ll]ink ]]; then
echo "$i"
fi
fi
done
)
if [[ ${#devices[@]} -eq 0 ]]; then
echo "⚠️ No Keychron non-Link HID devices found."
return 1
fi
if [[ -z $action ]]; then
echo "Usage: keychronctl <enable|disable>"
echo
echo "This will enable or disable all of the following devices:"
echo
printf ' %s\n' "${devices[@]}"
return 1
fi
echo "Found devices:"
printf ' %s\n' "${devices[@]}"
echo
for dev in "${devices[@]}"; do
case $action in
enable)
echo "✅ Enabling $dev (adding rw for group and others)..."
sudo chmod o+rw,g+rw "$dev"
ls -lah "$dev"
;;
disable)
echo "🚫 Disabling $dev (removing rw for group and others)..."
sudo chmod o-rw,g-rw "$dev"
ls -lah "$dev"
;;
*)
echo "❌ Unknown action: $action (use enable or disable)"
return 1
;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment