dotfiles/scripts/tginput.sh

56 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2023-08-20 11:21:03 +05:00
#!/bin/bash
2023-08-20 11:32:38 +05:00
if [[ $XDG_SESSION_TYPE != "x11" ]]; then
2023-08-20 12:01:56 +05:00
echo "Unsupported session type: $XDG_SESSION_TYPE"
exit 1
2023-08-20 11:32:38 +05:00
fi
2023-08-20 11:21:03 +05:00
get_tg_window_id(){
2023-08-20 12:00:53 +05:00
tg_window_id=$(wmctrl -lx | grep telegram-desktop | awk '{print $1}')
2023-08-20 11:21:03 +05:00
}
get_mouse_location(){
2023-08-20 12:00:53 +05:00
mouse_xy=$(xdotool getmouselocation --shell)
mouse_x=$(printf "%s\n" "$mouse_xy" | grep X= | cut -d= -f2)
mouse_y=$(printf "%s\n" "$mouse_xy" | grep Y= | cut -d= -f2)
2023-08-20 11:21:03 +05:00
}
return_mouse(){
2023-08-20 12:00:53 +05:00
xdotool mousemove $mouse_x $mouse_y
}
lock_tg(){
xdotool windowactivate --sync $tg_window_id key ctrl+l
}
2023-08-20 12:24:56 +05:00
read_passcode(){
if [[ ! -f $HOME/.local/.tgpasscode ]]; then
2023-08-20 12:27:28 +05:00
echo "Passcode file not found!, Enter Telegram local passcode seperated characters by space."
echo "Example: If passcode is 1234, then enter 1 2 3 4 "
2023-08-20 12:24:56 +05:00
read -p "Enter passcode: " PASSCODE
echo $PASSCODE > $HOME/.local/.tgpasscode
echo Telegram Passcode saved at: $HOME/.local/.tgpasscode
2023-08-20 12:15:35 +05:00
fi
2023-08-20 12:24:56 +05:00
tgpasscode=$(cat $HOME/.local/.tgpasscode)
2023-08-20 12:00:53 +05:00
}
unlock_tg(){
2023-08-20 12:24:56 +05:00
xdotool windowactivate --sync $tg_window_id key $tgpasscode Return
2023-08-20 11:21:03 +05:00
}
if [ "$1" == "lock" ]; then
2023-08-20 12:00:53 +05:00
get_tg_window_id
get_mouse_location
lock_tg
return_mouse
2023-08-20 11:21:03 +05:00
elif [ "$1" == "unlock" ]; then
2023-08-20 12:24:56 +05:00
read_passcode
2023-08-20 12:00:53 +05:00
get_tg_window_id
get_mouse_location
unlock_tg
return_mouse
2023-08-20 11:21:03 +05:00
else
2023-08-20 12:01:56 +05:00
echo "Invalid argument. Please use 'lock' or 'unlock'."
exit 1
2023-08-20 11:21:03 +05:00
fi