Skip to content

Add auto power profile switching for T2 MacBooks#5136

Open
fedesapuppo wants to merge 1 commit intobasecamp:devfrom
fedesapuppo:t2-power-profiles
Open

Add auto power profile switching for T2 MacBooks#5136
fedesapuppo wants to merge 1 commit intobasecamp:devfrom
fedesapuppo:t2-power-profiles

Conversation

@fedesapuppo
Copy link
Copy Markdown
Contributor

Summary

  • Adds omarchy-power-profile to switch between performance (AC) and power-saver (battery) profiles with audio feedback
  • Adds omarchy-wifi-powersave to toggle WiFi power save on/off
  • Installs udev rules to trigger both scripts on AC plug/unplug
  • Adds a boot service to set the correct profile at startup

Laptops 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

  • Run fix-t2.sh on a T2 MacBook
  • Unplug AC — verify profile switches to power-saver and unplug sound plays
  • Plug AC — verify profile switches to performance and plug sound plays
  • Reboot on battery — verify power-saver profile is set at boot
  • Verify WiFi power save is on when on battery, off when on AC

Copilot AI review requested due to automatic review settings March 27, 2026 21:27
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

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-powersave to accept on|off and pick a WiFi device via iw.
  • Add omarchy-power-profile to 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.

Comment thread install/config/hardware/apple/fix-t2.sh Outdated
Comment on lines +40 to +63
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"
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread install/config/hardware/apple/fix-t2.sh Outdated
Comment on lines +39 to +40
# Auto-switch power profile on AC plug/unplug
cat <<EOF | sudo tee /etc/udev/rules.d/95-power-profile.rules >/dev/null
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +59
# 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

Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@dhh dhh added the mac label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants