Skip to content

Instantly share code, notes, and snippets.

@allynt
Created September 9, 2020 13:47
Show Gist options
  • Save allynt/a701de4ba166adc3878a8c3adf772242 to your computer and use it in GitHub Desktop.
Save allynt/a701de4ba166adc3878a8c3adf772242 to your computer and use it in GitHub Desktop.
#!/bin/sh
# wrapper script for toggling fn keys on k380 keyboard in Linux (Xubuntu 19.04)
# `toggle_k380_functions_keys.sh` is bound to <alt>-<esc> in "keyboard -> application shortcuts"
# and I ensured that `/usr/local/bin/k380_conf` is configured to run w/ sudo's NOPASSWD option
# useful links:
# * https://askubuntu.com/questions/699138/logitech-k380-bluetooth-keyboard-make-function-keys-default
# * https://github.com/jergusg/k380-function-keys-conf
# * http://www.trial-n-error.de/posts/2012/12/31/logitech-k810-keyboard-configurator
# * https://askubuntu.com/questions/821919/how-do-i-add-sudo-commands-to-a-keyboard-shortcut
ADDRESS="046D:B342"
LOCKFILE="${0%.*}.lock"
DEVICE=`ls /sys/class/hidraw/ -l | grep $ADDRESS | grep -o 'hidraw[0-9]*$'`
if [ -z "$DEVICE" ]; then
echo "K380 does not seem to be connected. Try again later">&2;
exit;
fi
if [ -f "$LOCKFILE" ]; then
sudo k380_conf -d "/dev/$DEVICE" -f off;
rm $LOCKFILE;
else
sudo k380_conf -d "/dev/$DEVICE" -f on;
touch $LOCKFILE;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment