joshuagrisham / samsung-galaxybook-extras

Samsung Galaxybook Linux platform driver and accompanying utilities.
116 stars 15 forks source link

Simple script to turn Battery Saver on or off #17

Open enkiros opened 3 months ago

enkiros commented 3 months ago

This function was the only thing keeping me dual booting win 11, so incredible work here. Unfortunately, I can't seem to make it work reliably on my book2 NP750XED. Sometimes with the charger plugged in and battery saver on it doesn't start charging back even after dropping below 80% and I have to manually type the whole command to turn it off.

So I made a simple bash script that turns it on if it's off and vice versa using a single shortcut. Having no programming experience, this is basically half an hour's worth of reading stack overflow posts.

As I'm running hyprland on arch, I'm using dunst to send notifications to know if it's being turned on or off. I'm not sure how it would be translated to KDE or Gnome's notification daemon, but I believe using 'notify-send' should work in both.

_Note that this assumes the value of batterysaver is 0 for off by default

#!/bin/bash

if cat /sys/devices/platform/samsung-galaxybook/battery_saver | grep -q '0'; then
        echo 1 | pkexec tee /sys/devices/platform/samsung-galaxybook/battery_saver
        notify-send "Turning on battery saver"
        #dunstify "Turning on battery saver"
else
        echo 0 | pkexec tee /sys/devices/platform/samsung-galaxybook/battery_saver
        notify-send "Turning off battery saver"
        #dunstify "Turning off battery saver"
fi