Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Turn on/off device with xinput and zenity.
#!/usr/bin/zsh
setopt EXTENDED_GLOB
device="$(zenity --title="Select Device" --width=600 --height=500 --list --column="DEVICES" "${(f)$(xinput --list | ruby -e 'print ARGF.each.map {|i| i =~ /[^A-Za-z]*([A-za-z1-9 ]+[a-zA-Z0-9])\s*id=(\d+)/; "#$2 #$1\n" }.join.chomp')}"| perl -ne '/\d+/; print $&;')"
if (( $? == 0 )) && [[ -n $device ]]
then
action="$(zenity --list --column="ACTION" "turn on" "turn off")"
if (( $? == 0 )) && [[ -n $action ]]
then
if [[ $action == "turn off" ]]
then
backtime="$(zenity --title="Back time" --entry --text="Back after sec")"
if [[ "$backtime" == [0-9]## ]]
then
xinput set-int-prop $device "Device Enabled" 8 0
sleep $backtime
xinput set-int-prop $device "Device Enabled" 8 1
else
zenity --question --width=200 --text="Really turn off device $device?" && xinput set-int-prop $device "Device Enabled" 8 0
fi
else
xinput set-int-prop $device "Device Enabled" 8 1
fi
else
exit 1
fi
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.