toggle dark mode: 🔋 → 🌚 / 🔌 → ☀️
This example demonstrates a macOS automation script that toggles dark mode based on power source, checking every 60 seconds via a LaunchAgent plist. The Bash script uses `pmset` to detect whether the system draws from battery or AC power, and `defaults` to read the current appearance mode (Dark, Light, or Auto). It saves the original mode to a temporary file before enabling dark mode on battery, then reverts to the saved preference when power returns, using `osascript` to control System Events and display notifications. The code also handles Auto mode by writing the appropriate preference via `defaults write`.
AI-generated descriptionEvery 60s: toggle dark mode if on battery (save previous value). If back on power, revert to previous value.
NB: You'll get a notification when changed.
INSTALL
~/toggle_dark_mode.sh(don't forget tochmod u+xit)~/Library/LaunchAgents/com.user.toggle_dark_mode.plist