systemd-ac-power
Check AC power connection status
TLDR
Check AC power status
$ systemd-ac-power
Check with verbose output$ systemd-ac-power -v
SYNOPSIS
systemd-ac-power [OPTIONS]
DESCRIPTION
systemd-ac-power reports whether the computer is connected to an external power source (AC mains). It returns exit code 0 when on AC power and non-zero when on battery.This is useful in scripts and systemd unit conditions to change behavior based on power state.
PARAMETERS
-v, --verbose
Print "yes" or "no" to stdout in addition to exit code-h, --help
Display help
EXIT STATUS
0 - Running on AC powernon-zero - Running on battery or unable to determine
INSTALL
sudo apt install systemd
sudo dnf install systemd
sudo pacman -S systemd
sudo zypper install systemd
brew install systemd
nix profile install nixpkgs#systemd
CAVEATS
Requires proper power supply detection by the kernel. Some desktop systems without batteries always report AC power. Virtual machines may report power state incorrectly.
HISTORY
systemd-ac-power provides a simple, scriptable interface to power supply status, enabling power-aware behavior in systemd units and shell scripts.
