Add auto power profile switching for T2 MacBooks#5136
Add auto power profile switching for T2 MacBooks#5136fedesapuppo wants to merge 1 commit intobasecamp:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Adds T2 MacBook-specific automation to switch system power profiles and WiFi power-saving behavior based on AC/battery state, with audible feedback to confirm transitions.
Changes:
- Extend the T2 hardware installer to install/enable power profile management and add udev + boot-time hooks.
- Update
omarchy-wifi-powersaveto accepton|offand pick a WiFi device viaiw. - Add
omarchy-power-profileto set the appropriate power profile and play plug/unplug sounds.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| install/config/hardware/apple/fix-t2.sh | Adds udev rules + a boot service intended to drive power-profile and WiFi powersave switching on T2 MacBooks. |
| bin/omarchy-wifi-powersave | Refactors WiFi power-save toggling logic and CLI. |
| bin/omarchy-power-profile | New script to apply power profiles based on AC state and play feedback audio. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cat <<EOF | sudo tee /etc/udev/rules.d/95-power-profile.rules >/dev/null | ||
| SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="/usr/local/bin/omarchy-power-profile" | ||
| EOF | ||
|
|
||
| # Set correct power profile at boot | ||
| cat <<EOF | sudo tee /etc/systemd/system/power-profile-boot.service >/dev/null | ||
| [Unit] | ||
| Description=Set power profile based on AC status at boot | ||
| After=power-profiles-daemon.service | ||
| Requires=power-profiles-daemon.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/local/bin/omarchy-power-profile | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
| sudo systemctl enable power-profile-boot.service | ||
|
|
||
| # Toggle WiFi power save based on AC status | ||
| cat <<EOF | sudo tee /etc/udev/rules.d/99-wifi-powersave.rules >/dev/null | ||
| SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", RUN+="/usr/local/bin/omarchy-wifi-powersave off" | ||
| SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", RUN+="/usr/local/bin/omarchy-wifi-powersave on" |
There was a problem hiding this comment.
The udev rules and systemd unit reference /usr/local/bin/omarchy-power-profile and /usr/local/bin/omarchy-wifi-powersave, but Omarchy scripts are installed under $OMARCHY_PATH/bin (e.g., install.sh exports PATH="$OMARCHY_PATH/bin:$PATH"). As-is, these udev/systemd hooks will fail because the referenced binaries won’t exist. Use an absolute path that matches the actual install location (e.g., expand $OMARCHY_PATH/bin/... into the generated files at install time) or install/symlink the scripts into /usr/local/bin.
| # Auto-switch power profile on AC plug/unplug | ||
| cat <<EOF | sudo tee /etc/udev/rules.d/95-power-profile.rules >/dev/null |
There was a problem hiding this comment.
This adds a new /etc/udev/rules.d/95-power-profile.rules, but the installer already creates /etc/udev/rules.d/99-power-profile.rules in install/config/powerprofilesctl-rules.sh (run earlier from install/config/all.sh). Both rules will match and run, and the later 99-... rule will likely override the profile set by omarchy-power-profile, breaking the intended AC/battery behavior. Prefer overwriting/removing the existing 99-power-profile.rules for T2 machines (or gating the generic rule) so only one power-profile rule is active.
| # Auto-switch power profile on AC plug/unplug | |
| cat <<EOF | sudo tee /etc/udev/rules.d/95-power-profile.rules >/dev/null | |
| # Auto-switch power profile on AC plug/unplug (override generic 99-power-profile.rules for T2) | |
| cat <<EOF | sudo tee /etc/udev/rules.d/99-power-profile.rules >/dev/null |
| # Set correct power profile at boot | ||
| cat <<EOF | sudo tee /etc/systemd/system/power-profile-boot.service >/dev/null | ||
| [Unit] | ||
| Description=Set power profile based on AC status at boot | ||
| After=power-profiles-daemon.service | ||
| Requires=power-profiles-daemon.service | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/local/bin/omarchy-power-profile | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
| sudo systemctl enable power-profile-boot.service | ||
|
|
There was a problem hiding this comment.
After writing udev rules and a new systemd unit, the script doesn’t reload udev rules / trigger them, and it doesn’t run systemctl daemon-reload before enabling the new power-profile-boot.service. In other installer scripts (e.g., dell fix-xps-haptic-touchpad), daemon-reload is done explicitly. Add sudo udevadm control --reload-rules (or --reload) + a trigger for power_supply, and sudo systemctl daemon-reload before enabling the new unit so the changes take effect immediately and reliably.
7da5a74 to
26f21ae
Compare
Summary
omarchy-power-profileto switch between performance (AC) and power-saver (battery) profiles with audio feedbackomarchy-wifi-powersaveto toggle WiFi power save on/offLaptops should automatically prioritize battery life when unplugged and performance when on AC. The audio feedback (plug/unplug sounds from the freedesktop sound theme) confirms the switch happened. WiFi power save reduces battery drain but adds latency, so it's only enabled on battery.
The AC adapter is detected dynamically (different T2 models use different names), and the logged-in user UID is resolved at runtime rather than hardcoded.
Test plan
fix-t2.shon a T2 MacBook