PJ/buttons.sh
2024-12-26 15:19:33 -08:00

294 lines
4.3 KiB
Bash
Executable file

#!/bin/bash
shopt -s nocasematch #sets case insensitive option for the shell
websites=("youtube" "pbs")
### if no specific commands found run these
all(){
case $1 in
### navigation etc.
"play")
#sleep .5
xdotool_helper "key space"
;;
"fast_forward")
xdotool_helper "key Right"
;;
"rewind")
xdotool_helper "key Left"
;;
"forward" | "back" | "split_up" | "split_down")
sleep .1
echo "no default action assigned to $1"
;;
"split_right")
bluetoothctl disconnect 4C:B9:9B:11:4B:31
;;
"split_left")
sh /home/htpc/scripts/xrandr.sh
;;
### top buttons
"main" | "notification" | "settings" | "task_manager" | "search")
echo "no default action assigned to $1"
;;
"browser")
helper_find_or_open firefox
;;
"file_explorer")
helper_find_or_open kodi
;;
"action_center")
helper_find_or_open steam
;;
### arrow buttons
"desktop")
;;
"tasks")
;;
"sleep")
sh ~/scripts/PJ/cec.sh
;;
### test
"test")
#test code here, run with buttons.sh test
echo "sucessful test"
;;
*)
echo "unexpected action: ${1-}"
;;
esac
}
firefox_youtube(){
firefox_init
split_up(){
xdotool_helper "key f"
}
search(){
ff_search
}
play(){
echo "ffyt play"
xdotool_helper "key k"
}
desktop(){
ff_home "https://www.youtube.com"
}
split_right(){
xdotool_helper "key F11"
}
move_up(){
ff_home 'ext+container:name=hh&url=https://youtube.com'
}
forward(){
ff_home 'ext+container:name=fr&url=https://youtube.com'
}
}
firefox_pbs(){
firefox_init
split_up(){
xdotool_helper "mousemove 500 300"
xdotool_helper "click 1 click 1"
}
play(){
xdotool_helper "mousemove 500 300"
xdotool_helper "click 1"
}
desktop(){
ff_home "https://www.pbs.org"
}
}
Kodi(){
play(){
kodi-send --action="PlayPause"
}
forward(){
kodi-send --action="SkipNext"
}
back(){
kodi-send --action="SkipPrevious"
}
split_up(){
xdotool_helper "key p"
}
move_up(){
xdotool_helper "key o"
}
search(){
kodi-send --action="VideoLibrary.Search"
}
desktop(){
kodi-send --action="PreviousMenu"
}
refresh(){
kodi-send --action="UpdateLibrary(video)"
}
notification(){
kodi-send --action="ShowSubtitles"
}
settings(){
kodi-send --action="ActivateWindow(10123)"
for i in {0..3}
do
kodi-send --action="Down"
done
kodi-send --action="Select"
}
fast_forward(){
kodi-send --action="NextPreset"
}
rewind(){
kodi-send --action="PreviousPreset"
}
split_right(){
kodi-send --action="LockPreset"
}
file_explorer(){
kodi-send --action="ActivateWindow(12901)"
}
}
steam_bp(){
desktop(){
xdotool_helper "key alt+Enter"
}
}
steam_lp(){
desktop(){
xdotool_helper "mousemove 1872 13"
xdotool_helper "click 1"
}
}
Xfdesktop(){
search(){
rofi -modi drun,run -show drun
}
next(){
xfdesktop -N
}
}
Spotify(){
play(){
xdotool_helper "key space"
}
forward(){
xdotool_helper "key XF86AudioNext"
}
back(){
xdotool_helper "key XF86AudioPrev"
}
}
#firefox(){
# echo "return and run all()"
#}
discord(){
play(){
xdotool_helper "key F12"
}
}
mousepad(){
echo "return and run all()"
}
other(){
echo "return and run all()"
}
### helpers
firefox_init(){
ff_home(){
#xdg-open $1
firefox $1
sleep .1
xdotool_helper "key ctrl+shift+Tab"
sleep .1
xdotool_helper "key ctrl+w"
}
ff_search(){
sleep .2
xdotool_helper "key slash"
sleep .2
xdotool_helper "key ctrl+a"
sleep .2
xdotool_helper "key BackSpace"
}
}
helper_find_or_open() {
windows=$(wmctrl -l)
if [[ "$windows" == *"$1"* ]]; then
xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)"
else
nohup "$1" >/dev/null 2>&1 &
fi
}
xdotool_helper(){
sleep .2
xdotool $1
}
### get active window
target="$(xdotool getactivewindow getwindowclassname)"
if [[ "$target" == *"firefox"* ]]; then
name="$(xdotool getactivewindow getwindowname)"
for ws in "${websites[@]}"; do
if [[ "$name" == *"$ws"* ]]; then
target+="_$ws"
fi
done
elif [[ "$target" == *"steam"* ]]; then
name="$(xdotool getactivewindow getwindowname)"
if [[ "$name" == *"picture"* ]]; then
target+="_bp"
else
tagret+="_lp"
fi
fi
printf "action: %s\ntarget: %s\n" "$1" "$target"
### init target functions
$target
### find and run $1
if [[ $(type -t $1) == function ]]; then
$1
else
echo "program specific method not found calling all_$1"
all $1
#echo "unexpected action: ${1-}"
fi