The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 2,098     Votes:  5     ✅ Solution
Tags: power-management   shutdown   battery   automation  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

Title: How to shutdown automatically when AC power is not available
ID: /2016/11/29/How-to-shutdown-automatically-when-AC-power-is-not-available
Created: November 29, 2016    Edited:  April 9, 2019
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

Create a new rule in udev by opening the terminal and using:

gksu gedit /etc/udev/rules.d/50-ac-unplugged.rules

(If you are using Ubuntu 18.04 or a newer version gksu will not be available by default. In that situation please refer this question or use the above command as sudo -H gedit /etc/udev/rules.d/50-ac-unplugged.rules)

Put in the following line:

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/sbin/shutdown now"

Save the file and then restart udev services with:

sudo udevadm control --reload-rules

Save all your work and unplug your power supply.

⇧ How do I customize the context menu in Nautilus? Wake up monitor from standby and show the screen without blocking further standby [Ubuntu 16.04]  ⇩