From ad9315f166055222eee509cf0796de9a9dd5850c Mon Sep 17 00:00:00 2001 From: zerf58 Date: Fri, 13 Jun 2025 16:12:54 -0700 Subject: [PATCH 01/10] fix init --- init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index 5459682..1f40279 100755 --- a/init.sh +++ b/init.sh @@ -7,8 +7,8 @@ rm /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 -export $(grep -v '^#' /home/htpc/scripts/PJ/xml/secrets.env | xargs) -envsubst < /home/htpc/scripts/PJ/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml +export $(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs) +envsubst < /home/htpc/scripts/PJ/xml/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml # disable the power button on PJ, ignore if already commented # this usually doesn't revert, but occasionally does after updating system From 3a60983070b7f1ce286596b3792a94522716df5b Mon Sep 17 00:00:00 2001 From: zerf58 Date: Fri, 13 Jun 2025 16:25:23 -0700 Subject: [PATCH 02/10] better log handling --- .gitignore | 2 +- buttons.sh | 15 +- debug | 607 ----------------------------------------------------- 3 files changed, 5 insertions(+), 619 deletions(-) delete mode 100644 debug diff --git a/.gitignore b/.gitignore index 88f200c..ac670fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /secrets.env /tv_state - +/debug diff --git a/buttons.sh b/buttons.sh index bc4d6ed..5c3bce1 100755 --- a/buttons.sh +++ b/buttons.sh @@ -5,26 +5,19 @@ button=$1 debug(){ debug=$ROOT/debug + # todo: + # this keeps the log file at 30 lines but breaks the pipe when doing "tail -F debug" + tail -n 30 $debug > debug.tmp && mv debug.tmp $debug echo $1 echo $1>>$debug } -# debugging -#tail -n 30 "$debug" > tmp && cp tmp "$debug" + active=$(bash $ROOT/get_active_window.sh) debug "" debug "$(date +%s)" debug "active: $active" debug "button: $button" -# source the app folder -#APPS="$(pwd)/apps" -#if [ -d "$APPS" ]; then -# for file in "$APPS"/*; do -# if [ -f "$file" ]; then -# . "$file" -# fi -# done -#fi . $ROOT/find_or_open.sh . $ROOT/apps/default_commands.sh if [ -f "$ROOT/apps/${active%%_*}.sh" ]; then diff --git a/debug b/debug deleted file mode 100644 index 92020d5..0000000 --- a/debug +++ /dev/null @@ -1,607 +0,0 @@ -/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 From 847ecd02141c413a4d1793727a18e5d81aa5f2f4 Mon Sep 17 00:00:00 2001 From: htpc <> Date: Fri, 13 Jun 2025 16:38:13 -0700 Subject: [PATCH 03/10] stop this from blocking site specific actions --- apps/firefox.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/firefox.sh b/apps/firefox.sh index 502f77e..01a57c9 100644 --- a/apps/firefox.sh +++ b/apps/firefox.sh @@ -1,6 +1,6 @@ -firefox(){ - debug "no op for ff on this website" -} +#firefox(){ +# debug "no op for ff on this website" +#} firefox_youtube(){ # fullscreen split_up(){ From fa119a8d4f3d41adfefc0a96f345141bf7f362ff Mon Sep 17 00:00:00 2001 From: zerf58 Date: Wed, 18 Jun 2025 09:27:25 -0700 Subject: [PATCH 04/10] allow running find_or_open as standalone --- apps/default_commands.sh | 10 +++++----- apps/kodi.sh | 6 ++++-- find_or_open.sh | 6 +++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/default_commands.sh b/apps/default_commands.sh index 8eabb61..c7878d8 100644 --- a/apps/default_commands.sh +++ b/apps/default_commands.sh @@ -27,16 +27,16 @@ all(){ ### top buttons "main" | "notification" | "settings" | "task_manager" | "search") - echo "no default action assigned to $1" + echo "button all_$1 is no-op" ;; "browser") - helper_find_or_open firefox + find_or_open firefox ;; "file_explorer") - helper_find_or_open kodi + find_or_open kodi ;; "action_center") - helper_find_or_open steam + find_or_open steam ;; ### arrow buttons @@ -56,7 +56,7 @@ all(){ echo "sucessful test" ;; *) - echo "unexpected action: ${1-}" + echo "button $1 not found" ;; esac diff --git a/apps/kodi.sh b/apps/kodi.sh index 0951544..8883a9c 100644 --- a/apps/kodi.sh +++ b/apps/kodi.sh @@ -10,10 +10,12 @@ kodi(){ kodi-send --action="SkipPrevious" } split_up(){ - xdotool_helper "key p" + sleep .2 + xdotool key p } move_up(){ - xdotool_helper "key o" + sleep .2 + xdotool key o } search(){ kodi-send --action="VideoLibrary.Search" diff --git a/find_or_open.sh b/find_or_open.sh index 20851d4..3d0a0b6 100755 --- a/find_or_open.sh +++ b/find_or_open.sh @@ -1,5 +1,5 @@ #!/bin/bash -helper_find_or_open(){ +find_or_open(){ windows=$(wmctrl -l) if [[ "${windows,,}" == *"$1"* ]]; then xdotool windowactivate "$(wmctrl -l | grep -i "$1" | cut -d " " -f 1)" @@ -9,3 +9,7 @@ helper_find_or_open(){ echo "opening $1" fi } + +if [[ ! -z $1 ]]; then + find_or_open $1 +fi From d7accc8c69ef47cce856564313b2b95df08aebaf Mon Sep 17 00:00:00 2001 From: fred <> Date: Wed, 18 Jun 2025 09:47:16 -0700 Subject: [PATCH 05/10] shellcheck tweaks --- buttons.sh | 19 ++++++++++--------- find_or_open.sh | 4 ++-- init.sh | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/buttons.sh b/buttons.sh index 5c3bce1..9eba770 100755 --- a/buttons.sh +++ b/buttons.sh @@ -1,15 +1,16 @@ #!/bin/bash -export ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -button=$1 +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +export ROOT=ROOT +button="$1" debug(){ debug=$ROOT/debug # todo: # this keeps the log file at 30 lines but breaks the pipe when doing "tail -F debug" tail -n 30 $debug > debug.tmp && mv debug.tmp $debug - echo $1 - echo $1>>$debug + echo "$1" + echo "$1">>$debug } active=$(bash $ROOT/get_active_window.sh) @@ -28,18 +29,18 @@ else fi ### find and run $1 -if [[ $(type -t $active) == function ]]; then +if [[ $(type -t "$active") == function ]]; then debug "found $active methods" - $active + "$active" else debug "no $button method found in $active" fi -if [[ $(type -t $button) == function ]]; then +if [[ $(type -t "$button") == function ]]; then debug "found $button" - $1 + "$1" else debug "program specific method not found calling all $button" - all $1 + all "$1" fi diff --git a/find_or_open.sh b/find_or_open.sh index 3d0a0b6..0cef0bd 100755 --- a/find_or_open.sh +++ b/find_or_open.sh @@ -10,6 +10,6 @@ find_or_open(){ fi } -if [[ ! -z $1 ]]; then - find_or_open $1 +if [[ -n $1 ]]; then + find_or_open "$1" fi diff --git a/init.sh b/init.sh index 1f40279..c1d0490 100755 --- a/init.sh +++ b/init.sh @@ -7,7 +7,7 @@ rm /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 -export $(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs) +export "$(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs)" envsubst < /home/htpc/scripts/PJ/xml/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml # disable the power button on PJ, ignore if already commented From c467b52cfe5c9fd45a48dbda397ea2226bf88226 Mon Sep 17 00:00:00 2001 From: zerf58 Date: Wed, 18 Jun 2025 09:54:29 -0700 Subject: [PATCH 06/10] more shellcheck --- buttons.sh | 10 +++++----- init.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buttons.sh b/buttons.sh index 9eba770..66968bf 100755 --- a/buttons.sh +++ b/buttons.sh @@ -1,19 +1,19 @@ #!/bin/bash ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -export ROOT=ROOT +export ROOT="$ROOT" button="$1" debug(){ - debug=$ROOT/debug + debug="$ROOT"/debug # todo: # this keeps the log file at 30 lines but breaks the pipe when doing "tail -F debug" - tail -n 30 $debug > debug.tmp && mv debug.tmp $debug + tail -n 30 "$debug" > debug.tmp && mv debug.tmp "$debug" echo "$1" - echo "$1">>$debug + echo "$1">>"$debug" } -active=$(bash $ROOT/get_active_window.sh) +active=$(bash "$ROOT"/get_active_window.sh) debug "" debug "$(date +%s)" debug "active: $active" diff --git a/init.sh b/init.sh index c1d0490..1f40279 100755 --- a/init.sh +++ b/init.sh @@ -7,7 +7,7 @@ rm /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 -export "$(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs)" +export $(grep -v '^#' /home/htpc/scripts/PJ/secrets.env | xargs) envsubst < /home/htpc/scripts/PJ/xml/advancedsettings.xml > /home/htpc/.kodi/userdata/advancedsettings.xml # disable the power button on PJ, ignore if already commented From 1ad241d6e1c8b20c7b80dc483ecd386275acca49 Mon Sep 17 00:00:00 2001 From: zerf58 Date: Wed, 18 Jun 2025 10:10:22 -0700 Subject: [PATCH 07/10] add freetube --- apps/firefox.sh | 2 ++ apps/freetube.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 apps/freetube.sh diff --git a/apps/firefox.sh b/apps/firefox.sh index 01a57c9..01bfc04 100644 --- a/apps/firefox.sh +++ b/apps/firefox.sh @@ -4,6 +4,7 @@ firefox_youtube(){ # fullscreen split_up(){ + sleep .2 xdotool key f } search(){ @@ -11,6 +12,7 @@ firefox_youtube(){ search } play(){ + sleep .2 xdotool key k } # kiosk diff --git a/apps/freetube.sh b/apps/freetube.sh new file mode 100644 index 0000000..e2fec77 --- /dev/null +++ b/apps/freetube.sh @@ -0,0 +1,29 @@ +# fullscreen +split_up(){ + sleep .2 + xdotool key f +} +search(){ + sleep .2 + xdotool key alt+d + sleep .1 + xdotool key BackSpace +} +play(){ + sleep .2 + xdotool key k +} + +# TOD) setup profiles +# go to yt.com in shared container +desktop(){ + echo "placeholder" +} +# open hh container +back(){ + echo "placeholder" +} +# open fr container +forward(){ + echo "placeholder" +} From cfbdca17d8bea8e5606fc5b474c53515f0ff14ef Mon Sep 17 00:00:00 2001 From: fred <> Date: Wed, 18 Jun 2025 13:26:52 -0700 Subject: [PATCH 08/10] README --- README.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ cec.sh | 2 +- find_or_open.sh | 2 ++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2030744 --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ + +## Overview: +This is a project I made to control a home theater PC (HTPC) with a pepper jobs remote control with customized commands on the buttons on a per-app basis using bash scripts. + +The pepper jobs remote buttons are mapped to common windows shortcuts. Depending on your desktop environment some of these will work as generic shortcuts in linux out of the box, but my goal was to make the buttons behave differently depending on which app is active. +For example: +when firefox is open to the site youtube.com, pressing the search button will type "/" to move focus to the search bar at the top of the screen and type "control+a" to select all then type "BackSpace" to clear any text in it so you can flip the remote and start typing; +In kodi the same button will open a kodi search menu by executing: kodi-send --action="VideoLibrary.Search". + +### Parts list: + +Beelink Ser5 Mini PC: +![beelink](https://kagi.com/proxy/Beelink-SER5.jpg?c=Sry64v3AQdbrqAk1MK4X_IpvYWn_9QPQIHyBL3hdg54PbzBSdWDk3bhAaEiq5NccxPtgmHKAh0Wl7bXyQ9OoBWb-qtRbj6TyTVJ4gtlogBgnigcspYPiYT6yA6ZJZ8PdXo3RkxoGm4TmahnNk3LK8w%3D%3D) + +[Pepper Jobs Remote](https://www.pepper-jobs.com/products/w10-gyro-smart-remote) +![pepper_jobs](https://www.pepper-jobs.com/cdn/shop/files/img_01_03ca82de-33a6-4ec7-b523-a32e7a952a0e_540x.jpg?v=1614291123) + +[Pulse eight usb-hdmi-cec-adapter](https://www.pulse-eight.com/p/104/usb-hdmi-cec-adapter) +![ced-adapter](https://www.pulse-eight.com/generated-assets/products/0000381.jpeg) + +The computer could be anything, the hardware requirements are what you want to do with it. + +The cec adapter is optional, but allows the computer to turn the tv on and off via software which is mapped to the power button on the remote. It is also not necessary if running on a raspberry pi since cec is built into the hardware. + +### OS: +I am running endeavouros on the computer, but this could be any linux distro with the following software installed. + +### Software: +#### required: +xorg +xfce4 +xdotool +wmctrl + +#### optional: +libcec # for cec controls +kodi +freetube +spotify +\# other apps etc... + + +### How it works: +1. The button shortcuts are mapped in xfce to run the buttons.sh script when pressed. +2. buttons.sh runs get_active_window.sh to find what program is active. +3. It then looks for this program in the scripts in the app folder and inits it if it finds it. +4. After that it will look for the button that was pressed in the app script that was just loaded +5. If it finds that button in the app script it will run the code in the method +6. If it does not find the button in there it will look for the button in apps/default_commands.sh and run it if it finds it. + +### Notes: +My goal with this project was to make it as easy as possible to hop in and modify how any button works in any program. In order to add a new program you make a new sh file file in /apps with the name returned by get_active_window.sh. In that file make a method with the programed name (see list below) of any button that you want to remap with the code you want to run. + +For an example of further segementing button presses in an app, ie firefox has different methods when on youtube.com vs pbs.org, see: get_active_window.sh and apps/firefox.sh + +find_or_open.sh will check running programs, if what it is looking for is running already it will give it focus, if it is not it will launch the program. + +When possible I will use commands that will preform the desired actions in the specified software. If that is not possible instead I simulate key presses using xdotool to use keyboard shortcuts provided by the application. + +debug output goes to both the debug file and stdout when the buttons.sh script is run. This way troubleshooting can happen both on the command line when manually running buttons.sh and also in the debug file when testing buttons on the remote. + +There is an init.sh script that will copy the xfce4 shortcuts to the .config folder as well as a kodi config file. It also disables the XF86PowerOff button in Xorg. Without this the power button caused the remote to lock up until the system was rebooted even if XF86PowerOff was set to do nothing in xfce. After this the power button can be repurposed to run the cec.sh script to turn the tv on and off. + +some buttons are left as globals, ie, close is alt+f4, tab is left and in xfce config, cycle_windows_key is remapped to just tab instead of standard alt + tab, so this button can be used to cycle through open programs. + +### Button Names: +\# if no comment these name correspond to the words on the remote +sleep, # power +main, +notification, +search, +settings, +action_center, +file_explorer, +desktop, +refresh, +browser, +task_manager, +move_up, +play, +forward, +back, +fast_forward, +rewind +split_up, # bottom row left +split_down, # bottom row left middle +split_left, # bottom row right middle +split_right, # bottom row right + +#### Future Plans: +In the future I plan to migrate this project to Nixos diff --git a/cec.sh b/cec.sh index cd99355..e265e17 100755 --- a/cec.sh +++ b/cec.sh @@ -13,7 +13,7 @@ tv_off() { if [[ -z "$1" ]]; then if grep -q off ~/scripts/PJ/tv_state; then tv_on - elif grep -q on ~/scripts/PJ/tv_state; then + else tv_off fi elif [[ $1 = "on" ]]; then diff --git a/find_or_open.sh b/find_or_open.sh index 0cef0bd..60d73e4 100755 --- a/find_or_open.sh +++ b/find_or_open.sh @@ -10,6 +10,8 @@ find_or_open(){ fi } +# this can either be sourced by buttons.sh or run as a standalone script +# when running as a standalone, execute it: if [[ -n $1 ]]; then find_or_open "$1" fi From 61b06082d09b390bcffde41fb6bc3ce4c7bbb6f2 Mon Sep 17 00:00:00 2001 From: fred <> Date: Wed, 18 Jun 2025 19:38:40 -0700 Subject: [PATCH 09/10] update readme --- README.md | 115 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 2030744..d4846ab 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,94 @@ ## Overview: -This is a project I made to control a home theater PC (HTPC) with a pepper jobs remote control with customized commands on the buttons on a per-app basis using bash scripts. +This project is designed to control a home theater PC (HTPC) with a pepper jobs remote control. -The pepper jobs remote buttons are mapped to common windows shortcuts. Depending on your desktop environment some of these will work as generic shortcuts in linux out of the box, but my goal was to make the buttons behave differently depending on which app is active. -For example: -when firefox is open to the site youtube.com, pressing the search button will type "/" to move focus to the search bar at the top of the screen and type "control+a" to select all then type "BackSpace" to clear any text in it so you can flip the remote and start typing; -In kodi the same button will open a kodi search menu by executing: kodi-send --action="VideoLibrary.Search". +The buttons on the remote control are hard coded to common windows shortcuts, depending on the desktop environment some of these will work as generic shortcuts in linux out of the box, but this project aims to expand their functionality and provide custom commands based on the application that has focus. + +For example: when firefox is open to the site youtube.com, pressing the search button will type "/" to move focus to the search bar at the top of the screen and type "control+a" to select all then type "BackSpace" to clear any text in it so you can flip the remote and start typing; In kodi the same button will open a kodi search menu by executing: kodi-send --action="VideoLibrary.Search". + +Another goal of this project is to simplify modifications by allowing easy customization of button actions within applications. To add a new program, simply create a new .sh file in /apps with the name returned by get_active_window.sh and define methods within this file with the commands to run when the buttons are pressed. ### Parts list: -Beelink Ser5 Mini PC: -![beelink](https://kagi.com/proxy/Beelink-SER5.jpg?c=Sry64v3AQdbrqAk1MK4X_IpvYWn_9QPQIHyBL3hdg54PbzBSdWDk3bhAaEiq5NccxPtgmHKAh0Wl7bXyQ9OoBWb-qtRbj6TyTVJ4gtlogBgnigcspYPiYT6yA6ZJZ8PdXo3RkxoGm4TmahnNk3LK8w%3D%3D) +Beelink Ser5 Mini PC -[Pepper Jobs Remote](https://www.pepper-jobs.com/products/w10-gyro-smart-remote) -![pepper_jobs](https://www.pepper-jobs.com/cdn/shop/files/img_01_03ca82de-33a6-4ec7-b523-a32e7a952a0e_540x.jpg?v=1614291123) + -[Pulse eight usb-hdmi-cec-adapter](https://www.pulse-eight.com/p/104/usb-hdmi-cec-adapter) -![ced-adapter](https://www.pulse-eight.com/generated-assets/products/0000381.jpeg) +Pepper Jobs Remote + + + +Pulse eight usb-hdmi-cec-adapter + +

The computer could be anything, the hardware requirements are what you want to do with it. The cec adapter is optional, but allows the computer to turn the tv on and off via software which is mapped to the power button on the remote. It is also not necessary if running on a raspberry pi since cec is built into the hardware. ### OS: -I am running endeavouros on the computer, but this could be any linux distro with the following software installed. +I am running EndeavourOS on the computer, but this could be any linux distro with the following software installed. ### Software: #### required: -xorg -xfce4 -xdotool -wmctrl +Xorg
+xfce4
+xdotool
+wmctrl
#### optional: -libcec # for cec controls -kodi -freetube -spotify -\# other apps etc... +libcec # for cec controls
+kodi
+freetube
+spotify
+\# other apps etc...
### How it works: -1. The button shortcuts are mapped in xfce to run the buttons.sh script when pressed. -2. buttons.sh runs get_active_window.sh to find what program is active. -3. It then looks for this program in the scripts in the app folder and inits it if it finds it. -4. After that it will look for the button that was pressed in the app script that was just loaded -5. If it finds that button in the app script it will run the code in the method -6. If it does not find the button in there it will look for the button in apps/default_commands.sh and run it if it finds it. +1. The button combos that are hardcoded on the remote are mapped as keyboard shortcuts in xfce to run the buttons.sh script with the button name as $1 when pressed +2. buttons.sh runs get_active_window.sh to find what program is active +3. It then looks for this program in the scripts in the app folder and initializes it if it finds it +4. next it will execute the method with the pressed button name if it finds it in the file it just sourced and exit +5. If it does not find the button it will look for the button in apps/default_commands.sh and run it if it finds it ### Notes: -My goal with this project was to make it as easy as possible to hop in and modify how any button works in any program. In order to add a new program you make a new sh file file in /apps with the name returned by get_active_window.sh. In that file make a method with the programed name (see list below) of any button that you want to remap with the code you want to run. +find_or_open.sh will check running programs, if what it is looking for is running already it will give it focus, if it is not it will launch the program. + +When possible I am using commands that will preform the desired actions in the specified software. If that is not possible instead I simulate key presses using xdotool to use keyboard shortcuts provided by the application. For an example of further segementing button presses in an app, ie firefox has different methods when on youtube.com vs pbs.org, see: get_active_window.sh and apps/firefox.sh -find_or_open.sh will check running programs, if what it is looking for is running already it will give it focus, if it is not it will launch the program. - -When possible I will use commands that will preform the desired actions in the specified software. If that is not possible instead I simulate key presses using xdotool to use keyboard shortcuts provided by the application. - -debug output goes to both the debug file and stdout when the buttons.sh script is run. This way troubleshooting can happen both on the command line when manually running buttons.sh and also in the debug file when testing buttons on the remote. +Debug output goes to both the debug file and stdout when the buttons.sh script is run. This way troubleshooting can happen both on the command line when manually running buttons.sh and also in the debug file when testing buttons on the remote. There is an init.sh script that will copy the xfce4 shortcuts to the .config folder as well as a kodi config file. It also disables the XF86PowerOff button in Xorg. Without this the power button caused the remote to lock up until the system was rebooted even if XF86PowerOff was set to do nothing in xfce. After this the power button can be repurposed to run the cec.sh script to turn the tv on and off. -some buttons are left as globals, ie, close is alt+f4, tab is left and in xfce config, cycle_windows_key is remapped to just tab instead of standard alt + tab, so this button can be used to cycle through open programs. +Some buttons are left as globals:
+close is alt+f4,>br? +tab is tab. Additionally, in xfce config, cycle_windows_key is remapped to just tab instead of standard alt + tab, so this button can be used to cycle through open programs. ### Button Names: -\# if no comment these name correspond to the words on the remote -sleep, # power -main, -notification, -search, -settings, -action_center, -file_explorer, -desktop, -refresh, -browser, -task_manager, -move_up, -play, -forward, -back, -fast_forward, -rewind -split_up, # bottom row left -split_down, # bottom row left middle -split_left, # bottom row right middle -split_right, # bottom row right +\# if no comment the name matches the word(s) on the remote
+sleep, # power
+main,
+notification,
+search,
+settings,
+action_center,
+file_explorer,
+desktop,
+refresh,
+browser,
+task_manager,
+move_up,
+play,
+forward,
+back,
+fast_forward,
+rewind,
+split_up, # bottom row left
+split_down, # bottom row left middle
+split_left, # bottom row right middle
+split_right, # bottom row right
#### Future Plans: In the future I plan to migrate this project to Nixos From d187c37f032d0bd9e083226c3bed1589ec0450c9 Mon Sep 17 00:00:00 2001 From: zerf58 Date: Wed, 2 Jul 2025 09:02:46 -0700 Subject: [PATCH 10/10] dont run find_or_open when sourcing --- find_or_open.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/find_or_open.sh b/find_or_open.sh index 60d73e4..a787092 100755 --- a/find_or_open.sh +++ b/find_or_open.sh @@ -11,7 +11,6 @@ find_or_open(){ } # this can either be sourced by buttons.sh or run as a standalone script -# when running as a standalone, execute it: -if [[ -n $1 ]]; then - find_or_open "$1" +if [ "${BASH_SOURCE[0]}" = "$0" ] && [[ -n $1 ]]; then + find_or_open "$1" fi