Reputation: 257
I want to make a some kind of alert to let me know when the charger has disconnected (the cable doesn't fit into the socket well).
I have this to detect the status of the charger:
cat /sys/class/power_supply/ADP1/online
it returns 1 when charging and 0 when on battery.
and this to request a pop-up window:
zenity --info --text="Charger unplugged!"
I figured some kind of if statement would do the job, having to run it infinitely every second or so.
Then I remembered my days of Arduino where you could program an interrupt, that could trigger the script to run, rather than having to run it all the time.
Not sure what the best way to achieve this is. Does anybody know?
Many thanks.
Upvotes: 1
Views: 902
Reputation: 291
You could create a service, or you can do it in a more simple and primitive way: create a script that will create a fork, redirect it's own stdout
and stderr
to /dev/null
and execute an infinite loop that will be constantly checking your /sys/class/power_supply/ADP1/online
file. When the value is 0
it will redirect the stdout
and stderr
to the original, in order to show the prompt. To make this an autonomous script, you would have to execute it with crontab @reboot
.
I think that in the CLI it should work, but I don't know if it would work in a Graphical Desktop Interface
Upvotes: 1