You are not logged in.
Pages: 1
Hi there,
What do you consider the best way to run programs depending on the AC state, i.e. whether the laptop runs on battery or is plugged in?
Example use cases:
* Running my backup program only when I am plugged in
* Running Dropbox when I am mobile, thus on battery
Thanks for sharing your solutions!
Offline
How about a rule under udev?
This is what I use for increasing/decreasing backlight depending on AC state:
cat /etc/udev/rules.d/98-backlight.rules# Adjust screen brightness according to power state
# 1st rule for when on AC
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/xbacklight -set 90"
# 2nd rule for when on battery
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/xbacklight -set 35"4X Intel(R) Xeon(R) CPU E7-8870 @ 2.40GHz; 256GiB; 11TB EXT4; SL6.8
2X Intel(R) Xeon(R) CPU E5-2680 @ 2.70GHz; 256GiB; 3.4TB EXT4; SL6.8
Thinkpad X250; Broadwell-ULT Core i5; 8GiB, 525GB Crucial_CT525MX3; Arch
Thinkpad T440S; Haswell-ULT Core i7; 12GiB, 512GB SanDisk X210; Arch
Offline
I think udev rules would only be useful for reacting to events. The question sounds more like a conditional test to check the current state:
[[ $(cat /sys/class/power_supply/AC/online) -eq 1 ]] && command-to-run-on-AC-only"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Trilby,
Good point. A conditional test makes more sense in the context of the OP's question.
Halocaridina
4X Intel(R) Xeon(R) CPU E7-8870 @ 2.40GHz; 256GiB; 11TB EXT4; SL6.8
2X Intel(R) Xeon(R) CPU E5-2680 @ 2.70GHz; 256GiB; 3.4TB EXT4; SL6.8
Thinkpad X250; Broadwell-ULT Core i5; 8GiB, 525GB Crucial_CT525MX3; Arch
Thinkpad T440S; Haswell-ULT Core i7; 12GiB, 512GB SanDisk X210; Arch
Offline
Pages: 1