flashScreen (4111B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #!/bin/bash # NAME: flash-primary-screen.sh # PATH: ~/bin # DESC: Flashes primary screen colours to alert timer has ended. # DATE: November 15, 2018 # NOTE: Written for: https://askubuntu.com/a/1092835/307523 # I'm looking for a command to flash screens (if possible in colors) # Change 6 variables below to control screen flashing levels MaxBright="1.5" MinBright=".5" MaxRed="2.0" MaxGreen="2.0" MaxBlue="2.0" MinGamma=".5" declare aXrandr=() # Next two functions lifted from: eyesome internet sunrise/sunset time screen # brightness and gamma controller: https://github.com/WinEunuuchs2Unix/eyesome InitXrandrArray () { # Array is used for each monitor and searched by name. # Save time to search on connected/disconnected, primary monitor, # brightness level, gamma level. mapfile -t aXrandr < <(xrandr --verbose --current) } # InitXrandrArray SearchXrandrArray () { # Parms: $MonXrandrName = xrandr monitor name to search for. # NOTE: Entries in array follow predicatble order from xrandr --verbose: # <MONITOR-NAME> connected / disconnected (line 1 of monitor entry) # Gamma: 0.99:0.99:0.99 (line 5 of entry) # Brightness: 0.99 (line 6 of entry) # CRTC: 9 (line 8 of entry) fNameFnd=false fBrightnessFnd=false fGammaFnd=false fCrtcFnd=false XrandrConnection=disconnected XrandrPrimary=false XrandrGamma="" XrandrBrightness="" XrandrCRTC="" # Laptop lid open value=0, lid closed=blank for (( i=0; i<"${#aXrandr[*]}"; i++ )) ; do line="${aXrandr[$i]}" # Have we looped to next monitor and not found search string? if [[ "$line" =~ " connected " ]] && [[ $fNameFnd == true ]] ; then break fi if [[ "$line" =~ ^"$MonXrandrName connected" ]]; then fNameFnd=true XrandrConnection=connected [[ "$line" =~ "primary" ]] && XrandrPrimary=true fi if [[ $fNameFnd == true ]] && [[ $fGammaFnd == false ]] ; then if [[ "$line" =~ "Gamma: " ]]; then fGammaFnd=true XrandrGamma="${line##* }" # TODO: Use `xgamma` for accuracy fi fi if [[ $fGammaFnd == true ]] && [[ $fBrightnessFnd == false ]] ; then if [[ "$line" =~ "Brightness: " ]]; then fBrightnessFnd=true XrandrBrightness="${line##* }" fi fi if [[ $fBrightnessFnd == true ]] && [[ $fCrtcFnd == false ]] ; then if [[ "$line" =~ "CRTC: " ]]; then fCrtcFnd=true XrandrCRTC="${line##* }" break fi fi done } # SearchXrandrArray FlipBright () { if [[ $NewBrightness == "$MaxBright" ]] ; then NewBrightness="$MinBright" else NewBrightness="$MaxBright" fi } # FlipBright CleanUp() { xrandr --output "$MonXrandrName" --gamma "$SaveGamma" \ --brightness "$SaveBrightness" # Compensate for bug in Xrandr as of Nov 15, 2018 with second call InitXrandrArray SearchXrandrArray xrandr --output "$MonXrandrName" --gamma "$XrandrGamma" exit 0 } # CleanUp Main () { trap CleanUp INT TERM # Get primary monitor current settings XrandrName=$(xrandr --current | grep primary) MonXrandrName="${XrandrName%% *}" InitXrandrArray SearchXrandrArray # Did we find primary monitor ok? if [[ $fBrightnessFnd == false ]] || [[ $fGammaFnd == false ]] ; then echo "Internal Error: Could not find Primary Screen brightness or gamma" echo XrandrPrimary: "$XrandrPrimary" echo aXrandr[0]: "${aXrandr[0]}" echo Brightness: "$XrandrBrightness" echo Gamma: "$XrandrGamma" exit 2 fi # Restore these values when CleanUping program SaveBrightness="$XrandrBrightness" SaveGamma="$XrandrGamma" #Blink for 10 seconds end=$((SECONDS+10)) while [ $SECONDS -lt $end ]; do if [[ $Red == true ]] ; then Red=false Green=true NewGamma="$MaxRed:$MinGamma:$MinGamma" FlipBright elif [[ $Green == true ]] ; then Green=false NewGamma="$MinGamma:$MaxGreen:$MinGamma" FlipBright else Red=true NewGamma="$MinGamma:$MinGamma:$MaxBlue" FlipBright fi xrandr --output "$MonXrandrName" --gamma "$NewGamma" \ --brightness "$NewBrightness" sleep .2 done CleanUp } # Main Main "$@" |