Suspend Scripts for the Toshiba Tecra M2
As you may know if you are a regular reader I own a Toshiba Tecra M2. One of the things that annoyed me was I had to turn the brightness up every time my computer came out of standby mode. A fix for this is to adjust the brightness every time the computer comes out of standby mode.
The script is intended to be run under cron. I have mine set up to suspend after 5 minutes of the lid being closed.
if [ $(cat /proc/acpi/button/lid/LID/state | sed 's/state: //') == "closed" ]; then VAR=$(cat /proc/acpi/toshiba/lcd | sed 's/brightness: //' grep -v levels); sudo su -c "echo mem > /sys/power/state"; if [ $VAR -eq 1 ]; then ACTION=ADD; elif [ $VAR -eq 7 ]; then ACTION=SUB; else ACTION=ADD; fi; if [ $ACTION == "ADD" ]; then VAR=$(($VAR + 1)); else VAR=$(($VAR - 1)); fi; sudo su -c "echo brightness:$(echo $VAR) > /proc/acpi/toshiba/lcd"; fi; |
I run this with the following cron entry:
*/5 * * * * sh hibernate.sh |
The script first checks the current brightness. If the brightness is currently 1 or 7 it adjusts the mathematic operation so that when the laptop is opened the brightness is adjusted. Basically if the brightness is one, it adds one. If the brightness is 7 or any other value it subtracts one. This is currently working out quite well for me. I don’t know how useful this is to any body else, unless you happen to have a Toshiba that is doing the same thing but it should give you a good overall idea of how to perform basic mathematic operations in bash.