๐ฏ 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