Re: Can I Hear a Sound When Switching on the Monitor?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On July 30, 2018, Linux for blind general discussion wrote:
> Well, since this monitor just  has a button which tottles on/off,

While I'm not sure how to do it in a pure console environment, you
might check the output of `xrandr` both with the monitor on and the
monitor off.  If you get different output, you could poll the output
in a background script and play a sound accordingly.  So, assuming
your test is "does the output contain the text LDVS-1 connected", you
might do something like

#!/bin/sh
PREV_STATUS=0
ON_SOUND=$HOME/sounds/monitor_on.wav
OFF_SOUND=$HOME/sounds/monitor_off.wav
PLAYER=/usr/bin/aplay
while true
do
  xrandr | fgrep -q 'LVDS-1 connected'
  STATUS=$?
  if [ "$STATUS" -ne "$PREV_STATUS" ]
  then
    [ "$STATUS" -eq 1 ] && $PLAYER "$ON_SOUND" || $PLAYER "$OFF_SOUND"
    STATUS=$PREV_STATUS
  fi
  sleep 2s;
done


Putting this shell-script in a file and running it (adjusting the
"grep -q LVDS" for whatever tests the output of xrandr, and the
variables at the top for whatever sounds and player you want.

-tim



_______________________________________________
Blinux-list mailing list
Blinux-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/blinux-list



[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]