This commit is contained in:
zerf58 2025-06-13 16:09:14 -07:00
parent a31e08bd5f
commit 388924ed6e
16 changed files with 951 additions and 294 deletions

79
apps/default_commands.sh Normal file
View file

@ -0,0 +1,79 @@
### if no specific commands found run these
all(){
case $1 in
### navigation etc.
"play")
sleep .3
xdotool key space
;;
"fast_forward")
sleep .2
xdotool key Right
;;
"rewind")
sleep .2
xdotool key Left
;;
"forward" | "back" | "split_up" | "split_down")
debug "no op"
;;
"split_right")
bluetoothctl disconnect 4C:B9:9B:11:4B:31
;;
"split_left")
toggle_res
;;
### 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")
debug "no op"
;;
"tasks")
debug "no op"
;;
"sleep")
sh ~/scripts/PJ/cec.sh
;;
### test
"test")
#test code here, run with buttons.sh test
echo "sucessful test"
;;
*)
echo "unexpected action: ${1-}"
;;
esac
}
toggle_res(){
display=$(xrandr --listmonitors | grep -o '\S*$' | tail -n 1)
current_res=$(xrandr | grep "$display" | grep -o '[0-9]*x[0-9]*' | head -n 1)
res_1080p="1920x1080"
res_4k="3840x2160"
if [ "$current_res" = "$res_1080p" ]; then
target_res="$res_4k"
elif [ "$current_res" = "$res_4k" ]; then
target_res="$res_1080p"
fi
debug "Switching to: $target_res"
xrandr --output "$display" --mode "$target_res"
}

7
apps/discord.sh Normal file
View file

@ -0,0 +1,7 @@
discord(){
play(){
sleep .2
xdotool key F12
}
}

74
apps/firefox.sh Normal file
View file

@ -0,0 +1,74 @@
firefox(){
debug "no op for ff on this website"
}
firefox_youtube(){
# fullscreen
split_up(){
xdotool key f
}
search(){
helpers
search
}
play(){
xdotool key k
}
# kiosk
split_right(){
xdotool key F11
}
# go to yt.com in shared container
desktop(){
helpers
firefox 'ext+container:name=shared&url=https://youtube.com'
close_last_tab
}
# open hh container
back(){
helpers
firefox 'ext+container:name=hh&url=https://youtube.com'
close_last_tab
}
# open fr container
forward(){
helpers
firefox 'ext+container:name=fr&url=https://youtube.com'
close_last_tab
}
}
firefox_pbs(){
firefox_init
split_up(){
xdotool mousemove 500 300
xdotool click 1 click 1
}
play(){
xdotool mousemove 500 300
xdotool click 1
}
desktop(){
helpers
home "https://www.pbs.org"
}
}
### helpers
helpers(){
close_last_tab(){
sleep .2
xdotool key ctrl+shift+Tab
sleep .1
xdotool key ctrl+w
}
search(){
sleep .2
xdotool key slash
sleep .2
xdotool key ctrl+a
sleep .2
xdotool key BackSpace
}
}

53
apps/kodi.sh Normal file
View file

@ -0,0 +1,53 @@
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)"
}
}

14
apps/spotify.sh Normal file
View file

@ -0,0 +1,14 @@
spotify(){
play(){
sleep .2
xdotool key space
}
forward(){
sleep .2
xdotool key XF86AudioNext
}
back(){
sleep .2
xdotool key XF86AudioPrev
}
}

17
apps/steam.sh Normal file
View file

@ -0,0 +1,17 @@
steam_bp(){
desktop(){
sleep .2
xdotool key alt+Enter
}
}
steam_lp(){
desktop(){
sleep .2
xdotool mousemove 1872 13
sleep .2
xdotool click 1
}
}

8
apps/vncviewer.sh Normal file
View file

@ -0,0 +1,8 @@
vncviewer() {
split_up(){
sleep .5
xdotool key F8
sleep .2
xdotool key F
}
}

9
apps/xfdesktop.sh Normal file
View file

@ -0,0 +1,9 @@
xfdesktop(){
search(){
rofi -modi drun,run -show drun
}
forward(){
xfdesktop -N
}
}

View file

@ -1,302 +1,52 @@
#!/bin/bash #!/bin/bash
shopt -s nocasematch #sets case insensitive option for the shell
websites=("youtube" "pbs")
export ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
button=$1
### if no specific commands found run these debug(){
all(){ debug=$ROOT/debug
case $1 in echo $1
### navigation etc. echo $1>>$debug
"play") }
#sleep .5 # debugging
xdotool_helper "key space" #tail -n 30 "$debug" > tmp && cp tmp "$debug"
;; active=$(bash $ROOT/get_active_window.sh)
"fast_forward") debug ""
xdotool_helper "key Right" debug "$(date +%s)"
;; debug "active: $active"
"rewind") debug "button: $button"
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 # source the app folder
"main" | "notification" | "settings" | "task_manager" | "search") #APPS="$(pwd)/apps"
echo "no default action assigned to $1" #if [ -d "$APPS" ]; then
;; # for file in "$APPS"/*; do
"browser") # if [ -f "$file" ]; then
helper_find_or_open firefox # . "$file"
;; # fi
"file_explorer") # done
helper_find_or_open kodi #fi
;; . $ROOT/find_or_open.sh
"action_center") . $ROOT/apps/default_commands.sh
helper_find_or_open steam if [ -f "$ROOT/apps/${active%%_*}.sh" ]; then
;; . "$ROOT/apps/${active%%_*}.sh"
debug "$active sourced"
### 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"
}
}
Vncviewer() {
split_up(){
xdotool_helper "key F8"
sleep .1
xdotool_helper "key F"
}
}
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 else
nohup "$1" >/dev/null 2>&1 & debug "no $active source found"
fi 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 ### find and run $1
if [[ $(type -t $1) == function ]]; then if [[ $(type -t $active) == function ]]; then
$1 debug "found $active methods"
$active
else else
echo "program specific method not found calling all_$1" debug "no $button method found in $active"
all $1 fi
#echo "unexpected action: ${1-}"
if [[ $(type -t $button) == function ]]; then
debug "found $button"
$1
else
debug "program specific method not found calling all $button"
all $1
fi fi

607
debug Normal file
View file

@ -0,0 +1,607 @@
/home/htpc/scripts/PJ
1749852338
test firefox firefox_youtube
desktop
/home/htpc/scripts/PJ
1749852353
test firefox firefox_youtube
desktop
/home/htpc/scripts/PJ
1749852354
test firefox firefox_youtube
desktop
/home/htpc/scripts/PJ
1749852462
desktop
/home/htpc/scripts/PJ
1749852550
test firefox firefox_youtube
/home/htpc/scripts/PJ
1749852604
test firefox firefox_youtube
/home/htpc/scripts/PJ
1749852608
test firefox firefox_youtube
/home/htpc/scripts/PJ
1749852609
test firefox firefox_youtube
desktop
/home/htpc/scripts/PJ
1749852611
test firefox firefox_youtube
search
/home/htpc/scripts/PJ
1749852615
test firefox firefox_youtube
desktop
/home/htpc/scripts/PJ
1749852624
test firefox firefox_youtube
desktop
1749852696
test firefox firefox_youtube
11111
1749852703
test firefox firefox_youtube
11111
home
1749852705
test firefox firefox_youtube
11111
desktop
1749852759
firefox_youtube
11111
desktop
1749852765
firefox_youtube
11111
search
1749852818
firefox_youtube
home
1749852819
firefox_youtube
home
1749852824
firefox_youtube
home
1749852846
firefox_youtube
desktop
1749852886
firefox_youtube
desktop
1749852907
firefox_youtube
desktop
1749852927
firefox_youtube
desktop
1749852946
firefox_youtube
desktop
1749853013
firefox_youtube
desktop
1749853048
firefox_youtube
desktop
1749853051
firefox_youtube
desktop
1749853057
firefox_youtube
back
1749853060
firefox_youtube
forward
1749853064
firefox_youtube
desktop
1749853085
firefox
desktop
1749853087
firefox
desktop
1749853090
firefox
desktop
1749853097
firefox
desktop
1749853117
xfdesktop
browser
1749853119
firefox
browser
1749853121
firefox
browser
1749853122
firefox
desktop
1749853149
firefox_youtube
desktop
1749853154
firefox
desktop
1749853182
firefox
desktop
1749853198
firefox
desktop
1749853200
firefox
desktop
1749853254
firefox
file_explorer
1749853482
kodi
desktop
target: kodi
no desktop method found in kodi
program specific method not found calling all desktop
1749853484
kodi
desktop
target: kodi
no desktop method found in kodi
program specific method not found calling all desktop
1749853552
kodi
desktop
target: kodi
no desktop method found in kodi
program specific method not found calling all desktop
1749853600
kodi
desktop
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853630
kodi
desktop
kodi sourced
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853765
active: kodi
button: desktop
kodi sourced
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853786
active: kodi
button: desktop
kodi sourced
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853788
active: kodi
button: desktop
kodi sourced
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853791
active: kodi
button: desktop
kodi sourced
active:
no desktop method found in kodi
program specific method not found calling all desktop
1749853891
active: kodi
button: desktop
kodi sourced
found kodi methods
found desktop
1749853980
active: xfdesktop
button: search
xfdesktop sourced
found xfdesktop methods
found search
1749853994
active: xfdesktop
button: forward
xfdesktop sourced
found xfdesktop methods
program specific method not found calling all forward
1749854004
active: xfdesktop
button: fast_forward
xfdesktop sourced
found xfdesktop methods
program specific method not found calling all fast_forward
1749854038
active: xfdesktop
button: forward
xfdesktop sourced
found xfdesktop methods
found forward
1749854040
active: xfdesktop
button: forward
xfdesktop sourced
found xfdesktop methods
found forward
1749854196
active: vncviewer
button: desktop
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktop
1749854224
active: vncviewer
button: desktop
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktop
1749854233
active: vncviewer
button: desktop
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktop
no op
1749854234
active: vncviewer
button: desktop
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktop
no op
1749854261
active: vncviewer
button: desktop
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktop
no op
1749854293
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854295
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854297
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854299
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854301
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854302
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854306
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854309
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854311
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854312
active: vncviewer
button: split_down
vncviewer sourced
found vncviewer methods
program specific method not found calling all split_down
1749854320
active: vncviewer
button: split_up
vncviewer sourced
found vncviewer methods
found split_up
1749854461
active: vncviewer
button: desktopp
vncviewer sourced
found vncviewer methods
program specific method not found calling all desktopp
1749855450
active: xfdesktop
button: browser
xfdesktop sourced
found xfdesktop methods
program specific method not found calling all browser
1749855455
active: firefox_youtube
button: desktop
firefox_youtube sourced
found firefox_youtube methods
found desktop
1749855458
active: firefox_youtube
button: desktop
firefox_youtube sourced
found firefox_youtube methods
found desktop
1749855464
active: firefox_youtube
button: desktop
firefox_youtube sourced
found firefox_youtube methods
found desktop
1749855472
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855479
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855481
active: firefox_youtube
button: forward
firefox_youtube sourced
found firefox_youtube methods
found forward
1749855572
active: firefox_youtube
button: file_explorer
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all file_explorer
1749855576
active: kodi
button: browser
kodi sourced
found kodi methods
program specific method not found calling all browser
1749855578
active: firefox_youtube
button: file_explorer
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all file_explorer
1749855579
active: kodi
button: file_explorer
kodi sourced
found kodi methods
found file_explorer
1749855580
active: kodi
button: file_explorer
kodi sourced
found kodi methods
found file_explorer
1749855581
active: kodi
button: browser
kodi sourced
found kodi methods
program specific method not found calling all browser
1749855582
active: firefox_youtube
button: browser
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all browser
1749855583
active: firefox_youtube
button: browser
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all browser
1749855584
active: firefox_youtube
button: browser
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all browser
1749855584
active: firefox_youtube
button: browser
firefox_youtube sourced
found firefox_youtube methods
program specific method not found calling all browser
1749855587
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855588
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855589
active: firefox_youtube
button: desktop
firefox_youtube sourced
found firefox_youtube methods
found desktop
1749855717
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855720
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855728
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855737
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855755
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855764
active: firefox_youtube
button: forward
firefox_youtube sourced
found firefox_youtube methods
found forward
1749855775
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855779
active: firefox_youtube
button: desktop
firefox_youtube sourced
found firefox_youtube methods
found desktop
1749855783
active: firefox_youtube
button: back
firefox_youtube sourced
found firefox_youtube methods
found back
1749855786
active: firefox_youtube
button: forward
firefox_youtube sourced
found firefox_youtube methods
found forward
1749855804
active: firefox_youtube
button: search
firefox_youtube sourced
found firefox_youtube methods
found search
1749855811
active: firefox_youtube
button: search
firefox_youtube sourced
found firefox_youtube methods
found search
1749856037
active: firefox
button: desktop
firefox sourced
found firefox methods
no op for ff on this website
program specific method not found calling all desktop
no op

11
find_or_open.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
helper_find_or_open(){
windows=$(wmctrl -l)
if [[ "${windows,,}" == *"$1"* ]]; then
xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)"
echo "found $1"
else
nohup "$1" >/dev/null 2>&1 &
echo "opening $1"
fi
}

28
get_active_window.sh Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
shopt -s nocasematch # ignore case for website titles
websites=("youtube" "youtube" "pbs")
### get active window
active="$(xdotool getactivewindow getwindowclassname)"
name="$(xdotool getactivewindow getwindowname)"
active="${active,,}"
case "$active" in
*"firefox" )
for ws in "${websites[@]}"; do
if [[ "$name" == *"$ws"* ]]; then
active+="_$ws"
break
fi
done
;;
*"steam")
if [[ "$name" == *"picture"* ]]; then
active+="_big"
else
active+="_little"
fi
;;
esac
echo "$active"

View file

@ -1,13 +1,13 @@
#!/bin/bash #!/bin/bash
rm /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml rm /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
ln /home/htpc/scripts/PJ/xfce4-keyboard-shortcuts.xml /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml ln /home/htpc/scripts/PJ/xml/xfce4-keyboard-shortcuts.xml /home/htpc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
rm /home/htpc/.kodi/userdata/keymaps/keyboard.xml rm /home/htpc/.kodi/userdata/keymaps/keyboard.xml
ln /home/htpc/scripts/PJ/keyboard.xml /home/htpc/.kodi/userdata/keymaps/keyboard.xml ln /home/htpc/scripts/PJ/xml/keyboard.xml /home/htpc/.kodi/userdata/keymaps/keyboard.xml
rm /home/htpc/.kodi/userdata/advancedsettings.xml rm /home/htpc/.kodi/userdata/advancedsettings.xml
export $(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs) export $(grep -v '^#' /home/htpc/scripts/PJ/xml/secrets.env | xargs)
envsubst < /home/htpc/scripts/PJ/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml envsubst < /home/htpc/scripts/PJ/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml
# disable the power button on PJ, ignore if already commented # disable the power button on PJ, ignore if already commented