How can I find out the power state(whether it’s plugged to a power source, or not) of a laptop running on Ubuntu? I need to use that info. to trigger a python script, so I want to know if there is a way to do this using Python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ubuntu has support for the acpi protocol. By using the
-bflag, you can get battery info. One way you may want to use this is:Having to parse the batteryinfo.txt file may be a bit of a pain. In addition you will have to set up permissions because normally
acpiis only run as root.