Skip to content

Add a power-source-change hook#5653

Open
pomartel wants to merge 2 commits into
basecamp:devfrom
pomartel:power-source-change-hooks
Open

Add a power-source-change hook#5653
pomartel wants to merge 2 commits into
basecamp:devfrom
pomartel:power-source-change-hooks

Conversation

@pomartel
Copy link
Copy Markdown
Contributor

@pomartel pomartel commented May 7, 2026

It would be useful to have a hook that triggers on power source change. I personally have two use cases:

  • Change the default power profiles on AC and battery
  • Add automatic display brightness adjustments (I know you're not a fan!)

The main change besides adding the hook to omarchy-powerprofile-set is that we have to set the HOME, PATH and OMARCHY_PATH in the UDEV rule and run it as the user instead of root to avoid privileges escalation.

If you like the idea, I could also add sample hooks.

Copilot AI review requested due to automatic review settings May 7, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new power-source-change hook that runs after omarchy-powerprofiles-set, and updates the udev-triggered systemd-run invocation to provide a usable environment (HOME, OMARCHY_PATH, PATH) for hook execution.

Changes:

  • Add omarchy-hook power-source-change "$action" invocation to omarchy-powerprofiles-set
  • Update udev rules generation to pass HOME, OMARCHY_PATH, and PATH into the systemd-run unit
  • Add a migration to re-apply the updated udev rule generation

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
migrations/1778159545.sh Re-sources the udev rule generation script so existing installs get updated env passing
install/config/powerprofilesctl-rules.sh Extends generated udev rules to set env vars for the transient unit
bin/omarchy-powerprofiles-set Triggers the new power-source-change hook after applying the selected profile

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install/config/powerprofilesctl-rules.sh Outdated
Comment on lines +3 to +7
run_path="$omarchy_path/bin:/usr/local/sbin:/usr/local/bin:/usr/bin"

cat <<EOF | sudo tee "/etc/udev/rules.d/99-power-profile.rules"
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set"
SUBSYSTEM=="power_supply", ATTR{type}=="USB", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set"
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --setenv=HOME=$HOME --setenv=OMARCHY_PATH=$omarchy_path --setenv=PATH=$run_path --property=After=power-profiles-daemon.service $omarchy_path/bin/omarchy-powerprofiles-set"
SUBSYSTEM=="power_supply", ATTR{type}=="USB", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --setenv=HOME=$HOME --setenv=OMARCHY_PATH=$omarchy_path --setenv=PATH=$run_path --property=After=power-profiles-daemon.service $omarchy_path/bin/omarchy-powerprofiles-set"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants