For some reason, my laptop's screen brightness does not update when I plug-in or plug-out the power supply. I've looked at quite a few solutions for that problem, but none of them seemed to work well. So, instead of despairing and giving up, I decided to try to turn this into a learning experience and see if I can't write a script that does it for me.
I tried figuring it out on my own, with some help from the internet, of course, but I'm pretty new to bash scripting and Ubuntu in general, so I didn't get far.
What I was able to figure out was that I can find the state of the battery with
$ upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep -E "state"
state: charging/discharging
depending on whether or not the AC adapter is plugged in. I don't know if that's even useful, but it's kinda cool, and I didn't know how to use grep
before, so what the hell, learning is fun.
Anyways, is there a somewhat clean way to do this? By "clean way" I just mean a way that one with limited bash script experience could comprehend.
One similar question I found that had a good answer is this one, which says the following:
When you plug in/out the AC adapter, the scripts in
/etc/pm/power.d
get called with >an argument: "true" (if you run on battery), or "false" (if you run with the power >adapter).
The problem is that I don't know how to access that argument from within a script. So, I guess it all boils down to a pretty simple problem, but I thought I'd post the question anyways, in case people had better solutions.