π― 1. Auto-Optimize macOS Performance Daily
πΉ Cleans junk files, flushes RAM, and empties logs every night
bash#!/bin/bash
echo "Cleaning up system..."
sudo purge
sudo rm -rf ~/Library/Caches/*
sudo rm -rf /Library/Caches/*
sudo find /private/var/log -type f -delete
echo "Done!"
π How to Automate:
- Save it as
cleanup.sh
- Make it executable: bashCopyEdit
chmod +x cleanup.sh
- Schedule it using
cron
or LaunchAgents (for GUI-based automation).
π 2. Auto-Limit Battery Charge to 80% (Extends Lifespan)
πΉ Prevents overcharging, useful for MacBooks
- Install AlDente: cssCopyEdit
brew install --cask aldente
- Set charge limit: arduinoCopyEdit
defaults write com.davidwernhart.AlDente MaxPercentage 80
π 3. Auto-Connect to WiFi & Mount a Network Drive on Boot
πΉ Useful for always-on access to a NAS or shared folder
bash#!/bin/bash
networksetup -setairportpower en0 on
mount_afp afp://username:password@192.168.1.100/SharedFolder /Volumes/Shared
π How to Automate:
- Save as
wifi_mount.sh
- Make executable: bashCopyEdit
chmod +x wifi_mount.sh
- Add to startup via LaunchAgents
πΆοΈ 4. Auto-Enable Dark Mode at Sunset & Light Mode at Sunrise
πΉ Matches macOS theme with real-world time
bash#!/bin/bash
hour=$(date +"%H")
if [ $hour -ge 18 ] || [ $hour -lt 6 ]; then
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to true'
else
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to false'
fi
π How to Automate:
- Save as
darkmode.sh
- Run every hour using
crontab -e
: pgsqlCopyEdit0 * * * * /path/to/darkmode.sh
πΎ 5. Auto-Backup Important Folders to External Drive
πΉ Syncs Documents & Desktop to an external drive every day
bash#!/bin/bash
rsync -av --delete ~/Documents /Volumes/BackupDrive/
rsync -av --delete ~/Desktop /Volumes/BackupDrive/
echo "Backup complete!"
π How to Automate:
- Add to LaunchAgents or run via
cron
.
π₯ 6. Auto-Close Unused Apps at Midnight
πΉ Saves memory by closing apps like Photoshop, Chrome, etc.
bash#!/bin/bash
apps=("Google Chrome" "Photoshop" "Slack" "Spotify")
for app in "${apps[@]}"; do
osascript -e "tell application \"$app\" to quit"
done
π How to Automate:
- Save as
close_apps.sh
- Run every night at midnight: pgsqlCopyEdit
0 0 * * * /path/to/close_apps.sh
π 7. Auto-Update Homebrew & macOS Software Weekly
πΉ Keeps your Mac & installed apps always up-to-date
bashCopyEdit#!/bin/bash
echo "Updating Homebrew..."
brew update && brew upgrade && brew cleanup
echo "Updating macOS..."
sudo softwareupdate -ia
π How to Automate:
- Run this every Sunday at 3 AM: pgsqlCopyEdit
0 3 * * 7 /path/to/update.sh