Keyboard-switch script
This commit is contained in:
parent
7a9d3d7adb
commit
7cd692a86b
4 changed files with 38 additions and 1 deletions
35
custom/keyboard-switch/default.nix
Normal file
35
custom/keyboard-switch/default.nix
Normal 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
|
||||
''
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue