Keyboard-switch script

This commit is contained in:
Filippo Berto 2023-05-10 14:22:34 +02:00
parent 7a9d3d7adb
commit 7cd692a86b
No known key found for this signature in database
GPG key ID: FE98AE5EC52B1056
4 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,35 @@
{ writeShellScriptBin
, lib
, xorg
, libnotify
, coreutils
, keyboard_name ? "AT Translated Set 2 keyboard"
}:
writeShellScriptBin "keyboard-switch" ''
config_folder=''${XDG_DATA_HOME:-~/.local/share}
fconfig="$config_folder/keyboard-switch.state"
PATH=$PATH:"${lib.makeBinPath [ coreutils xorg.xinput libnotify ]}"
if [ ! -f $fconfig ]; then
echo "Creating config file"
mkdir -p $config_folder
echo "enabled" > $fconfig
var="enabled"
else
read -r var< $fconfig
echo "keyboard is : ${keyboard_name}"
fi
if [ "$var" = "disabled" ]; then
notify-send "Enabling keyboard..." \ "ON - Keyboard connected !";
echo "enable keyboard..."
xinput enable "${keyboard_name}"
echo "enabled" > $fconfig
elif [ "$var" = "enabled" ]; then
notify-send "Disabling Keyboard" \ "OFF - Keyboard disconnected";
echo "disable keyboard"
xinput disable "${keyboard_name}"
echo 'disabled' > $fconfig
fi
''