script to toggle on/off a screen or monitor

Linux for blind general discussion blinux-list at redhat.com
Sat Apr 8 20:30:15 UTC 2023


Hello,

doing some house cleaning I came across the attached very small shell scripts
aptly named monitor-toggle. It just alternatively switch on and off the display
and say it using spd-say.

I do not remember who wrote it, but it's not me.

Didier
-- 
Didier Spaier
didieratslintdotfr
-------------- next part --------------
#!/bin/sh
output=$(xrandr | grep ' connected ' | awk '{print $1}' | head -1)
screenSize=$(xrandr | awk 'BEGIN {foundOutput=0}
    / '$output' / {foundOutput=1}
    /\*\+/ {print $1}
    /^[^ ]/ {if(foundOutput) exit 0}')
if [ "$screenSize" != "" ]; then
    xrandr --output $output --fb $screenSize --off
	spd-say 'monitor off'
else
    xrandr --output $output --auto
    spd-say 'Monitor on'
fi


More information about the Blinux-list mailing list