1

I hope someone can help me. I've got a pulse-eight cec adapterand my TV is my main monitor for PC.
I made 5 simple stand-alone scripts linked to F8 and up to F12 on the keyboard. They turn tv on-off and HDMI switch, but I would like to expand my idea a little. So I Made a Script that turns the TV Off (using cec command) when pc screen goes off but there is a problem with that. If I switch sources to watch TV that script will trigger and turn off in the middle of me watching a film.

I want to modify this guys script to do all the work but my grep foo isn't good enough :-(

I added < function filter_key2(){ grep "0f:80:30:00:30:00" <( echo "$3" ) > and the line below in the hopes to be able to only run < echo standby 0 | /usr/bin/cec-client -s > with is the line to turn tv off only when only when this line is triggered < if filter_key3 "$l"; then echo "source switched back" fi >

My tv does not report the active source but it does Broadcast routing change info if cec-client is running,

So how do make it work?

Next question is if this works cec-client script will be running in the background. How do I echo control stuff to cec-client from within the script? I can only have one instance of cec-client running how ever it can stay running always. I discovered that when it is running from terminal I can type "echo on 0 " whilst its displaying debug info and tv will turn on. This script below will need to take over the list I mentioned earlier with the F keys.

#!/bin/bash # Simple script to control your Raspberry Pi with your TV remote using libcec # # Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com> # GPL licensed (see the end of file) * Use at your own risk! # # You can set this to be run in your desktop "startup programs", or # at the last line of /etc/rc.local, just to say a couple options # # keys: # OK - launch kodi # up - launch browser # down - change wallpaper (this is a custom script of mine) # left - suspend my desktop computer # back - exit desktop session # # You can hit 'stop' to enter "mouse mode", or 'play' to exit it. # In "mouse mode" you can move around the mouse with the remote arrows, hit ok # to double-click. # # This is just an example to provide ideas, so you should change what each button does. # USER=user # user that will be logged in OSDCOLOR=red # color for xosd messages MOUSESPEED=50 # how many pixels a mouse will move on each press #dbg=echo # uncomment to just print the command without executing it VERBOSE=0 # print echov lines #DRY_RUN="yes" # uncomment to actually ignore button presses type cec-client &>/dev/null || { echo "cec-client is requiered"; exit; } type xdotool &>/dev/null || NOXDOTOOL=# trap "exit 1" INT #USR_CMD="su - $USER -c" #_XAUTH="/home/$USER/.Xauthority" function d(){ eval "$NOXDOTOOL $@" ; } function echov(){ [[ "$VERBOSE" == "1" ]] && echo $@ ; } function filter_key(){ grep -q "key pressed: $1 .* duration" <( echo "$2" ) ; } function mouse_move(){ XAUTHORITY="$_XAUTH" DISPLAY=:0 xdotool mousemove_relative -- $@; } function mouseclick(){ XAUTHORITY="$_XAUTH" DISPLAY=:0 xdotool click --repeat 2 1 ; } function osdecho(){ type osd_cat &>/dev/null && echo "$@" | XAUTHORITY="$_XAUTH" DISPLAY=:0 osd_cat -ptop -Acenter -c$OSDCOLOR; } function filter_key2(){ grep "0f:80:30:00:30:00" <( echo "$3" ) ; } function filter_key3(){ grep "0f:80:10:00:10:00" <( echo "$4" ) ; } while :; do | while read l; do echov $l [[ "$DRY_RUN" != "" ]] && continue # pgrep kodi && { echov "Ignoring key, because Kodi is running"; continue; } if filter_key2 "$l"; then echo "source switched away" fi if filter_key3 "$l"; then echo "source switched back" fi if filter_key "select" "$l"; then [[ "$MOUSEMODE" == "1" ]] && mouseclick || { $dbg echo "ok key press" } fi if filter_key "up" "$l"; then [[ "$MOUSEMODE" == "1" ]] && mouse_move 0 -$MOUSESPEED || \ $dbg echo "up key press" fi if filter_key "left" "$l"; then [[ "$MOUSEMODE" == "1" ]] && mouse_move -$MOUSESPEED 0 || \ $dbg echo "left key press" fi if filter_key "down" "$l"; then [[ "$MOUSEMODE" == "1" ]] && mouse_move 0 $MOUSESPEED || \ $dbg echo "down key press" fi if filter_key "right" "$l"; then [[ "$MOUSEMODE" == "1" ]] && mouse_move $MOUSESPEED 0 || \ $dbg echo "right key press" fi if filter_key "exit" "$l"; then { echo "exiting" killall cec-client killall cec-test.sh } fi if filter_key "stop" "$l"; then echo "mouse mode on" MOUSEMODE=1 fi if filter_key "play" "$l"; then echo "mouse mode off" MOUSEMODE=0 fi done done trap - INT exit 0 

Thanks in advance.

Please let me know if I should post my code I'm referring to to make it easier to understand.

2
  • 1
    Please write proper sentences with some more punctuation. It's hard to read and I stopped after some lines. Commented Feb 18, 2020 at 12:33
  • Sorry about the sentences. I hope it a bit clearer now. Commented Feb 18, 2020 at 19:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.