A powerful, exhaustive maintenance script specifically designed for MacBook Air 2016 running macOS Monterey 12.7.6. This script performs low-level system operations with high-level output, featuring progress tracking, risk assessment, detailed reporting, and comprehensive CLI support.
- ✨ 37 Operations (up from 23) - Comprehensive coverage
- 🎯 CLI Arguments - Full command-line support (--help, --verbose, --yes, etc.)
- 🔒 Enhanced Security - Security audit, privacy cleanup, backup verification
- 💾 Memory Management - Critical for 8GB RAM systems
- 📊 APFS Snapshots - Can free 10-50GB of space!
- 🌐 Network Diagnostics - Complete network health checks
- 🌡️ Thermal Monitoring - Temperature and fan status
- 📈 System Analysis - Large files, duplicates, startup optimization
- 🎨 HTML Reports - Beautiful visual reports in addition to Markdown
- 🛡️ Critical Fixes - Trap cleanup, disk space checks, caffeinate support
- ✅ Comprehensive Cleanup: Cache, logs, temporary files, and system debris
- ✅ System Rebuild: Spotlight, LaunchServices, kernel extensions, and font caches
- ✅ Optimization: Database optimization for Mail, Safari, Photos, browsers, and more
- ✅ Disk Management: Verification, repair, permission fixes, and APFS snapshot management
- ✅ Network Operations: DNS flush, network reset, daemon management, full diagnostics
- ✅ System Updates: Check for macOS, security, and application updates
- ✅ Hardware Health: Driver verification, firmware, thermal monitoring, and system diagnostics
- ✅ Memory Management: Analysis, optimization, and purge capabilities
- ✅ Security Audit: SIP, Gatekeeper, FileVault, Firewall, and permissions checks
- ✅ Privacy Cleanup: Remove sensitive data (history, recent items, Siri data)
- ✅ Progress Tracking: Real-time progress bar with ETA calculation
- ✅ Risk Assessment: Each operation shows LOW/MEDIUM/HIGH risk level
- ✅ User Confirmation: Confirm each category before execution (or auto-confirm)
- ✅ Timestamped Logging: Complete audit trail of all operations
- ✅ Dual Reports: Markdown AND HTML reports saved to Desktop
- ✅ CLI Support: Comprehensive command-line arguments
- ✅ Sudo Support: Automatic privilege escalation when needed
- ✅ Safety Features: Trap cleanup, disk space checks, caffeinate support
./mac_maintenance.sh./mac_maintenance.sh --help # Show help
./mac_maintenance.sh --list # List all operations
./mac_maintenance.sh --verbose # Enable debug output
./mac_maintenance.sh --yes # Auto-confirm all
./mac_maintenance.sh --only-risk LOW # Run only low-risk operations
./mac_maintenance.sh --operation <name> # Run specific operation
./mac_maintenance.sh --skip <operation> # Skip specific operation
./mac_maintenance.sh --version # Show version
./mac_maintenance.sh --no-color # Disable colors# Auto-confirm all operations with verbose output
./mac_maintenance.sh --verbose --yes
# Run only low-risk operations
./mac_maintenance.sh --only-risk LOW
# Run specific operation
./mac_maintenance.sh --operation security_audit
# Skip network reset
./mac_maintenance.sh --skip network_reset- Cache Cleanup - User, system, browser, and application caches
- Log Cleanup - System and application logs (keeps recent logs)
- Temporary Files - System and user temporary files
- DNS Flush - DNS cache and resolver cleanup
- Disk Check - Disk verification and SMART status
- Font Cache - Font cache cleanup and rebuild
- Dock Reset - Dock database and cache reset
- Thumbnail Cache - Icon and thumbnail cache cleanup
- QuickLook Cache - QuickLook cache and plugin refresh
- Login Items - Review and list login items
- Cache Cleanup - User, system, browser, and application caches
- Log Cleanup - System and application logs (keeps recent logs)
- Temporary Files - System and user temporary files
- DNS Flush - DNS cache and resolver cleanup
- Disk Check - Disk verification and SMART status
- Font Cache - Font cache cleanup and rebuild
- Dock Reset - Dock database and cache reset
- Thumbnail Cache - Icon and thumbnail cache cleanup
- QuickLook Cache - QuickLook cache and plugin refresh
- Login Items - Review and list login items
- System Updates - Check for macOS and security updates
- App Updates - Check Homebrew, App Store, npm, pip, gem updates
- Driver Check - Hardware diagnostics and driver verification
- Security Audit - 🆕 SIP, FileVault, Firewall, permissions checks
- Backup Verification - 🆕 Time Machine and iCloud status
- Network Diagnostics - 🆕 Complete network health check
- Thermal Monitoring - 🆕 CPU temperature and fan status
- Large File Finder - 🆕 Find files >100MB
- Duplicate Finder - 🆕 Scan for duplicate files
- Startup Optimization - 🆕 Analyze boot configuration
- Log Analysis - 🆕 Check for errors and kernel panics
- Spotlight Rebuild - Complete search index rebuild
- LaunchServices Rebuild - Application associations database
- Permission Repair - File permissions and ACLs
- Database Optimization - SQLite VACUUM and REINDEX for system databases
- Daemon Operations - System daemon reload and restart
- Mail Optimization - Mail envelope index and database optimization
- iCloud Cache - iCloud Drive and sync cache cleanup
- Language Cleanup - Remove unused language files (keeps English)
- Memory Management - 🆕 Memory analysis, VM stats, purge option
- APFS Snapshots - 🆕 Manage snapshots (can free 10-50GB!)
- App Cache Optimization - 🆕 Xcode, Docker, npm, Gradle, Python caches
- Browser Optimization - 🆕 Safari, Chrome, Firefox, Edge database optimization
- Privacy Cleanup - 🆕 Safari history, recent items, Siri data, clipboard
- Kernel Extensions - Kext cache rebuild (requires reboot)
- Network Reset - Complete network configuration reset
- System Updates Check - Check for macOS and security updates
- Application Updates Check - Check Homebrew, App Store, npm, pip, gem updates
- Driver & Hardware Check - Verify drivers, firmware, and system health
- Notification Center database cleanup
- iOS device backup management
- Software update cache clearing
- Printer cache cleanup
- Time Machine snapshot review
- Quarantine flags cleanup
- Dynamic linker cache update
- System integrity verification
- NVRAM diagnostics
- Hardware: MacBook Air 2016 (or compatible Mac)
- OS Version: macOS Monterey 12.7.6
- RAM: 8GB recommended
- Free Space: At least 5GB for safe operation
- Permissions: Sudo/admin access required
- Backup: Recent Time Machine or other backup (NO BACKUPS CREATED BY SCRIPT)
- Clone this repository:
git clone https://github.com/costaindustries-source/mac-cleaner.git
cd mac-cleaner- Make the script executable:
chmod +x mac_maintenance.sh./mac_maintenance.shThe script will:
- Display system information
- Request sudo privileges
- Present each operation category for confirmation
- Show risk level (LOW/MEDIUM/HIGH) for each category
- Display real-time progress with ETA
- Generate timestamped log file in
/tmp/ - Create detailed Markdown report on Desktop
For each operation category, you'll see:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Operation Category: cache_cleanup
Description: Clean system and user caches (browser, app, system)
Risk Level: LOW - Safe operation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Proceed with this operation? [Y/n]
- Press
YorEnterto proceed - Press
Nto skip the operation
Progress: [████████████████████░░░░░░░░░░░░░░░░░] 65% (13/20) ETA: 2m 15s - Cleaning font cache
- Location:
/tmp/mac_maintenance_YYYYMMDD_HHMMSS.log - Contains: Timestamped record of all operations
- Format:
[YYYY-MM-DD HH:MM:SS] INFO/ERROR/WARNING: Message
- Location:
~/Desktop/maintenance_report_YYYYMMDD_HHMMSS.md - Contains:
- Execution summary
- Space freed
- Operations performed
- Errors and warnings
- System recommendations
- Technical details
- System information
- Recent Time Machine backup
- Critical files backed up to external storage
- Cloud sync enabled for important documents
LOW Risk - Safe operations that can be run anytime:
- Cache cleanup
- Log cleanup
- Temporary files
- DNS flush
- Font cache
- Dock reset
MEDIUM Risk - May require application restart or brief system interruption:
- Spotlight rebuild
- LaunchServices rebuild
- Permission repair
- Database optimization
- Mail optimization
HIGH Risk - Significant system changes, restart recommended:
- Kernel extension cache rebuild
- Complete network reset
Safe to Delete (automatically removed):
- Browser caches (Safari, Chrome, Firefox)
- Application caches
- System cache files (SIP-safe)
- Old log files (keeps recent)
- Temporary files
- Download quarantine database
- Font caches
- Icon caches
- Thumbnail caches
NOT Deleted (preserved):
- User documents
- Application data
- Photos, Music, Movies
- Mail messages (only cache/index)
- System files
- Configuration files
- Keychain data
- WiFi passwords
- Restart Your Mac - Essential for kext cache and system changes
- Verify Applications - Ensure apps launch correctly
- Check Spotlight - Search indexing may take 10-30 minutes
- Open Mail - First launch may be slow (rebuilding index)
- Test Network - If network reset was performed
- Review Report - Check for any errors or warnings
- Weekly: Empty Trash, clear browser caches manually
- Monthly: Run this comprehensive maintenance script
- Quarterly: Check for macOS and app updates
- Annually: Consider clean macOS installation
# Make sure it's executable
chmod +x mac_maintenance.sh
# Check permissions
ls -l mac_maintenance.sh# Pre-authenticate
sudo -v
# Then run script
./mac_maintenance.sh- Check the log file in
/tmp/for detailed error messages - Some operations require System Integrity Protection (SIP) disabled
- Ensure sufficient disk space available
- Try running individual operations by confirming only specific categories
- Wait for Spotlight indexing to complete (check Activity Monitor for
mds_stores) - Restart your Mac if not already done
- Some databases rebuild on first app launch (normal)
Cache Management:
rm -rfon user/system cache directories- Package manager cache cleanup (brew, npm, pip, gem)
- Font cache database removal
- Application-specific cache cleanup
System Rebuilds:
mdutilfor Spotlight indexinglsregisterfor LaunchServiceskextcachefor kernel extensionsatsutilfor font cache
Database Operations:
- SQLite
VACUUMandREINDEXon system databases - Mail envelope index rebuild
- Safari, Photos, Calendar database optimization
Disk Operations:
diskutil verifyVolumefor verificationdiskutil repairVolumefor repairsdiskutil resetUserPermissionsfor permissions- SMART status checking
Network Operations:
dscacheutil -flushcachefor DNSkillall -HUP mDNSResponderfor respondernetworksetupfor configuration- ARP cache clearing
Daemon Management:
launchctlfor daemon control- System daemon kickstart
- User agent reload
- MacBook Air (13-inch, Early 2015)
- MacBook Air (13-inch, 2017)
- MacBook Pro (Retina, 13-inch, Early 2015)
- macOS Monterey 12.7.x
- macOS Big Sur 11.x
- macOS Catalina 10.15.x
- Other Intel-based Macs from 2015-2017 era
- Apple Silicon Macs (M1/M2/M3) - some operations differ
- macOS Ventura or newer - commands may have changed
- macOS Mojave or older - some commands not available
Feel free to open issues or submit pull requests for:
- Additional maintenance operations
- Bug fixes
- Compatibility improvements
- Documentation updates
This script is provided as-is for educational and maintenance purposes. Use at your own risk.
- Always maintain current backups
- Review operations before confirming
- Understand risk levels
- Test on non-production systems first
- Some operations may affect system stability if interrupted
The authors are not responsible for any data loss or system issues resulting from use of this script.
Created for comprehensive macOS maintenance on MacBook Air 2016, macOS Monterey 12.7.6.
Version: 1.0.0
Last Updated: November 2025
Status: Production Ready