How to check if the AC laptop adapter is plugged or not?
You can use acpi
with -a
argument. To see how it works, run in your terminal:
acpi -a
By default, acpi
package is not installed in Ubuntu, but is very easy and quickly to install from your terminal using the following command:
sudo apt-get install acpi
Then, in your script you can use for example:
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
if [ "$ac_adapter" = "on" ]; then
notify-send "AC Adapter" "The AC Adapter is on."
else
notify-send "AC Adapter" "The AC Adapter is off."
fi
To make the script to run at start up, just add a new entry in your crontab list (using crontab -e
command) as follow:
@reboot DISPLAY=:0.0 /path/to/your/script