Laptop scripts
04 March 2023On my laptop I use IceWM as my window manager and being pretty minimalist some laptop-specific functions I have had to access via the command-line. Having eventually got fed up of having some xterm windows open purely to do this I finally decided to put the functions into scripts that are called from the program menu rather than the command-line. The scripts make use of Xdialog in order to present a minimalist user interface.
Suspend and Hibernate
Suspend and hibernate both put the computer to sleep, the different being how deep it is. Suspend puts the system in a low-power mode where the CPU is deactivated but memory is still kept powered up, so when woken the system reactivates almost immediately. In contrast Hibernate writes the content of memory to disk and then switches the system off, and when it it turned on again the system is restored to the state it was in at time of hibernation.
System suspend script
#!/bin/bash Xdialog \ --title "Suspend computer" \ --yesno "\nSuspend computer system?\n" 0 0 if [ "$?" -eq 0 ]; then loginctl suspend fi
System hibernate script
#!/bin/bash Xdialog \ --title "Hibernate computer" \ --yesno "\nHibernate computer system?\n" 0 0 if [ "$?" -eq 0 ]; then loginctl hibernate fi
Screen brightness
Screen brightness is exactly that, how bright the screen is. I normally keep my screen relatively dim to save power , which is why the values I have selected are biased towards the low side, and I suspect this might also have helped extend the life of the laptop as a whole. There is nothing stopping anyone wanting to use these scripts from changing the values :)
#!/bin/bash VALUE=`Xdialog \ --title "Brightness" \ --radiolist "Set screen brightness" 26 27 0 \ "75" "75% brightness" off \ "50" "50% brightness" off \ "25" "25% brightness" off \ "15" "15% brightness" ON \ "10" "10% brightness" off \ "5" "5% brightness" off \ "1" "1% brightness" off \ 2>&1` if [ "$?" -eq 0 ]; then xbacklight "=${VALUE}" fi
Battery “life extender” mode
This may be a Samsung-specific thing but other laptops of the era may well have equivalent functions. With older laptop power batteries keeping them 100% charged for extended period of times actually shortens their life-space, so for times when laptops are kept plugged in there is a “life extender” that basically caps how much it can be charged to around the 70-80% mark.
#!/bin/bash if [ `cat /sys/devices/platform/samsung/battery_life_extender` -eq 0 ]; then ENABLE="off" DISABLE="ON" else ENABLE="ON" DISABLE="off" fi VALUE=`Xdialog \ --title "Laptop power" \ --radiolist "Enable battery life extender?" 13 35 2 \ "Enable" "Maximum 70% charge" $ENABLE \ "Disable" "Maximum full charge" $DISABLE 2>&1` if [ "$?" -eq 0 ]; then if [ "$VALUE" == "Enable" ]; then echo 1 > /sys/devices/platform/samsung/battery_life_extender else echo 0 > /sys/devices/platform/samsung/battery_life_extender fi fi
For this to work will require changing of permissions so the setting can be changed by a non-root user:$ sudo chmod 666 /sys/devices/platform/samsung/battery_life_extender