09-24-2020, 09:28 PM
(This post was last modified: 09-24-2020, 10:01 PM by elijahr.
Edit Reason: Better example
)
Thank you for the suggestion. I should have specified, I'm using Manjaro with i3 so I don't have the KDE settings.
I did find a way to listen for AC adapter events, using udev, something like this as a rule in /usr/lib/udev/rules.d/:
Then I ran sudo udevadm control --reload to reload the udev rules.
In my script, I check whether the AC adapter is plugged in with:
I did find a way to listen for AC adapter events, using udev, something like this as a rule in /usr/lib/udev/rules.d/:
Code:
ACTION=="change", SUBSYSTEM=="power_supply", RUN+="the_command"
Then I ran sudo udevadm control --reload to reload the udev rules.
In my script, I check whether the AC adapter is plugged in with:
Code:
#!/bin/sh
case $(cat /sys/devices/platform/dc-charger/power_supply/dc-charger/online) in
0)
# do something when unplugged
;;
1)
# do something when plugged in
;;
esac