Plug in AC power and switch profile automatically.
cargo build --release
cp systemd/plug-switch.service ~/.config/systemd/user/plug-switch.service
cp target/release/plug-switch ~/.local/bin/plug-switch
systemctl --user enable plug-switch
systemctl --user start plug-switchIt gets power events from UPower and changes power profile via power-profiles-daemon D-Bus.
While searching for a tool, I found a GNOME extension, but I couldn't install it due to versioning issues. Since extensions are prone to breaking with GNOME upgrades, I wanted a more robust tool. This led to the systemd service approach, GNOME may provide graphical UI for the tool's settings, but it can work without GNOME.
Another reason is the implementation detail. Other projects check if the battery is actively charging. However, a laptop might be plugged in but not charging if the battery is full or has reached a set threshold. This tool, instead, reacts purely to the AC power connection status, regardless of whether the battery is charging.
# whether ac is connected
zbus-xmlgen system org.freedesktop.UPower /org/freedesktop/UPower/devices/line_power_ACAD
# switch power profile
zbus-xmlgen system org.freedesktop.UPower.PowerProfiles /org/freedesktop/UPower/PowerProfiles
# whether battery is charging, not needed
zbus-xmlgen system org.freedesktop.UPower /org/freedesktop/UPower/devices/DisplayDevice
# legacy power profile service name
zbus-xmlgen system net.hadess.PowerProfiles /net/hadess/PowerProfilesrelated projects
- Auto-Switching Power Profiles When Plugging in Your Charger Using Power-Profiles-Daemon on Linux · Kobus van Schoor
- eliapasquali/power-profile-switcher: Gnome extension to automatically switch between power profiles based on power supply.
- dmy3k/auto-power-profile: Gnome extension to automatically switch between power profiles based on power supply.