⚡ Mac Optimizer Pro

Give your Mac a deep clean and tune-up, automated. Here's exactly what optimize_pro.sh does, step by step.

Bash macOS Free & open-source Requires sudo GPL-3.0
🧰 Good to know. This script goes deep, so a few steps clear things out for good (caches, logs, local Time Machine snapshots) — the same cleanup a power user would do by hand, just automated. As with any system maintenance, it's good practice to have a recent backup on hand. See the README for usage instructions.

Overview

optimize_pro.sh runs eight maintenance functions in sequence. After the user confirms, the script asks for the administrator password once (sudo -v) and then keeps the sudo session alive in the background for the whole run, so it doesn't prompt again at every step.

Procedure details

1 clean_caches — Cache cleanup Moderate impact

Removes the contents of system and user cache directories, and application log files.

sudo rm -rf /Library/Caches/*
rm -rf ~/Library/Caches/*
rm -rf ~/Library/Logs/*

Effect: frees disk space and forces applications to rebuild their caches on next launch (may slow their first startup).

2 clean_temp_files — System temporary files Light touch

Empties the temporary file directories used by the system and applications.

sudo rm -rf /private/var/tmp/*
sudo rm -rf /private/var/folders/*

Effect: purges volatile files that are normally recreated on demand.

3 purge_ram — RAM purge Light touch

Forces macOS to release inactive memory pages.

sudo purge

Effect: may temporarily slow down the system while memory caches are rebuilt.

4 flush_dns — DNS cache Light touch

Flushes the DNS resolver cache and restarts the resolver service.

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Effect: the next domain name lookups will be resolved from scratch.

5 clean_time_machine_snapshots — Local Time Machine snapshots Frees the most space

Lists and then deletes local snapshots created by Time Machine (restore points stored on the internal disk).

tmutil listlocalsnapshots /
sudo tmutil deletelocalsnapshots <snapshot>

Effect: frees the disk space used by these snapshots. Does not delete Time Machine backups on an external drive, but reduces the local restore points available.

6 maintain_homebrew — Homebrew maintenance Moderate impact

If Homebrew is installed, updates formulae, upgrades installed packages, removes orphaned dependencies, and cleans the cache.

brew update
brew upgrade
brew autoremove
brew cleanup -s

Effect: Homebrew packages are upgraded to their latest versions; the step is skipped if brew is not detected.

7 reindex_spotlight — Spotlight reindexing Moderate impact

Forces a full rebuild of the Spotlight search index for the main volume.

sudo mdutil -E /

Effect: Spotlight search may be temporarily unavailable or incomplete, and CPU usage may increase for several minutes while reindexing runs in the background.

8 repair_disk_permissions — Disk verification Light touch

Checks the integrity of the boot volume's file system.

diskutil verifyVolume /

Effect: read-only operation (verification, not automatic repair); may take several minutes.

Confirmation and completion

Before starting, the script displays a warning and asks for explicit confirmation (o/n, French for yes/no). After the eight steps complete, it recommends restarting the machine (sudo shutdown -r now) to fully apply the effects of the maintenance.