| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # backlight.sh |
| 3 | # reldate 02dec2011 |
| 4 | |
| 5 | # A bug in Fedora Core 16/17 messes up the keyboard backlight controls. |
| 6 | # This script is a quick-n-dirty workaround, essentially a shell wrapper |
| 7 | #+ for xrandr. It gives more control than on-screen sliders and widgets. |
| 8 | |
| 9 | OUTPUT=$(xrandr | grepscip-shell system . . grep. LV | awkscip-shell system . . awk. '{print $1}') # Get display name! |
| 10 | INCR=.05 # For finer-grained control, set INCR to .03 or .02. |
| 11 | |
| 12 | old_brightness=$(xrandr --verbose | grepscip-shell system . . grep. rightness | awkscip-shell system . . awk. '{ print $2 }') |
| 13 | |
| 14 | |
| 15 | if [scip-shell system . . `[`. -z "$1" ] |
| 16 | then |
| 17 | bright=1 # If no command-line arg, set brightness to 1.0 (default). |
| 18 | |
| 19 | else |
| 20 | if [scip-shell system . . `[`. "$1" = "+" ] |
| 21 | then |
| 22 | bright=$(echoscip-shell system . . echo. "scale=2; $old_brightness + $INCR" | bc) # +.05 |
| 23 | |
| 24 | else |
| 25 | if [scip-shell system . . `[`. "$1" = "-" ] |
| 26 | then |
| 27 | bright=$(echoscip-shell system . . echo. "scale=2; $old_brightness - $INCR" | bc) # -.05 |
| 28 | |
| 29 | else |
| 30 | if [scip-shell system . . `[`. "$1" = "#" ] # Echoes current brightness; does not change it. |
| 31 | then |
| 32 | bright=$old_brightness |
| 33 | |
| 34 | else |
| 35 | if [[ "$1" = "h" || "$1" = "H" ]] |
| 36 | then |
| 37 | echoscip-shell system . . echo. |
| 38 | echoscip-shell system . . echo. "Usage:" |
| 39 | echoscip-shell system . . echo. "$0 [No args] Sets/resets brightness to default (1.0)." |
| 40 | echoscip-shell system . . echo. "$0 + Increments brightness by 0.5." |
| 41 | echoscip-shell system . . echo. "$0 - Decrements brightness by 0.5." |
| 42 | echoscip-shell system . . echo. "$0 # Echoes current brightness without changing it." |
| 43 | echoscip-shell system . . echo. "$0 N (number) Sets brightness to N (useful range .7 - 1.2)." |
| 44 | echoscip-shell system . . echo. "$0 h [H] Echoes this help message." |
| 45 | echoscip-shell system . . echo. "$0 any-other Gives xrandr usage message." |
| 46 | |
| 47 | bright=$old_brightness |
| 48 | |
| 49 | else |
| 50 | bright="$1" |
| 51 | |
| 52 | fi |
| 53 | fi |
| 54 | fi |
| 55 | fi |
| 56 | fi |
| 57 | |
| 58 | |
| 59 | xrandr --output "$OUTPUT" --brightness "$bright" # See xrandr manpage. |
| 60 | # As root! |
| 61 | E_CHANGE0=$? |
| 62 | echoscip-shell system . . echo. "Current brightness = $bright" |
| 63 | |
| 64 | exit $E_CHANGE0 |
| 65 | |
| 66 | |
| 67 | # =========== Or, alternately . . . ==================== # |
| 68 | |
| 69 | #!/bin/bash |
| 70 | # backlight2.sh |
| 71 | # reldate 20jun2012 |
| 72 | |
| 73 | # A bug in Fedora Core 16/17 messes up the keyboard backlight controls. |
| 74 | # This is a quick-n-dirty workaround, an alternate to backlight.sh. |
| 75 | |
| 76 | target_dir=\ |
| 77 | /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/backlight/acpi_video0 |
| 78 | # Hardware directory. |
| 79 | |
| 80 | actual_brightness=$(catscip-shell system . . cat. $target_dir/actual_brightness) |
| 81 | max_brightness=$(catscip-shell system . . cat. $target_dir/max_brightness) |
| 82 | Brightness=$target_dir/brightness |
| 83 | |
| 84 | let "req_brightness = actual_brightness" # Requested brightness. |
| 85 | |
| 86 | if [scip-shell system . . `[`. "$1" = "-" ] |
| 87 | then # Decrement brightness 1 notch. |
| 88 | let "req_brightness = $actual_brightness - 1" |
| 89 | else |
| 90 | if [scip-shell system . . `[`. "$1" = "+" ] |
| 91 | then # Increment brightness 1 notch. |
| 92 | let "req_brightness = $actual_brightness + 1" |
| 93 | fi |
| 94 | fi |
| 95 | |
| 96 | if [scip-shell system . . `[`. $req_brightness -gt $max_brightness ] |
| 97 | then |
| 98 | req_brightness=$max_brightness |
| 99 | fi # Do not exceed max. hardware design brightness. |
| 100 | |
| 101 | echoscip-shell system . . echo. |
| 102 | |
| 103 | echoscip-shell system . . echo. "Old brightness = $actual_brightness" |
| 104 | echoscip-shell system . . echo. "Max brightness = $max_brightness" |
| 105 | echoscip-shell system . . echo. "Requested brightness = $req_brightness" |
| 106 | echoscip-shell system . . echo. |
| 107 | |
| 108 | # ===================================== |
| 109 | echoscip-shell system . . echo. $req_brightness > $Brightness |
| 110 | # Must be root for this to take effect. |
| 111 | E_CHANGE1=$? # Successful? |
| 112 | # ===================================== |
| 113 | |
| 114 | if [scip-shell system . . `[`. "$?" -eq 0 ] |
| 115 | then |
| 116 | echoscip-shell system . . echo. "Changed brightness!" |
| 117 | else |
| 118 | echoscip-shell system . . echo. "Failed to change brightness!" |
| 119 | fi |
| 120 | |
| 121 | act_brightness=$(catscip-shell system . . cat. $Brightness) |
| 122 | echoscip-shell system . . echo. "Actual brightness = $act_brightness" |
| 123 | |
| 124 | scale0=2 |
| 125 | sf=100 # Scale factor. |
| 126 | pct=$(echoscip-shell system . . echo. "scale=$scale0; $act_brightness / $max_brightness * $sf" | bc) |
| 127 | echoscip-shell system . . echo. "Percentage brightness = $pct%" |
| 128 | |
| 129 | exit $E_CHANGE1 |