How to Check All Your Apps for Homebrew Availability

I don't think there is any question on how useful the free Mac
package manager, Homebrew, can be. You
can download and install an app with just one simple terminal command,
something like:
brew install bbedit
After it's installed, there is no ZIP archive or DMG file to clean up or manage. To update you apps installed with Homebrew, you don't need a special app or a subscription to anything. You just open a terminal windows and run:
brew upgrade
Your apps will be upgraded in place with nothing for you to clean up. To back up your configuration, you just run
brew bundle dump
and a custom brewfile will be created at the root of your home directory. If you get a new Mac od do a fresh install on your current machine, you can use that brewfile to download all your apps and packages with one command.
If you are late to the party and already have an /Applications folder full of your favorite apps, don't worry, you can use a simple shell script to compare what you have installed with what is available for the Homebrew catalog. It won't take long to replace your manually installed apps with their Homebrew counterparts.
How To Check Your Applications Folder
Here is the script. It isn't 100% foolproof, so read the explanation and don't empty your trash until you've verified that the app you got from Homebrew is the same as the app you replaced.
\# List all applications in /Applications and ~/Applications find /Applications -maxdepth 1 -type d -name "*.app" -print0 | while IFS= read -r -d $'\0' app_path; do app_name=$(basename "$app_path" .app) echo "Checking: $app_name" \# Sanitize the app name for Homebrew search (replace spaces with hyphens, etc.) search_term=$(echo "$app_name" | sed -e 's/ /-/g' -e 's/\./-/g' -e 's/@.*//') \# Basic sanitization, might need more \# Search Homebrew formulae brew search "$search_term" | grep -i "^$search_term$" && echo " Found in Homebrew formulae" \# Search Homebrew casks brew search --cask "$search_term" | grep -i "^$search_term$" && echo " Found in Homebrew casks" done
Explanation:
- The script finds all .app directories in /Applications and ~/Applications.
- It extracts the application name.
- It performs basic sanitization of the name to make it more suitable for a Homebrew search.
- It uses brew search and brew search --cask to look for matches in both Homebrew formulae (command-line tools and libraries) and casks (GUI applications).
- The grep -i "^$search_term$" part tries to find exact matches (case-insensitive).
How to use:
- Save the script to a file (e.g., check_brew_availability.sh).
- Make it executable: chmod +x check_brew_availability.sh.
- Run it from your terminal: ./check_brew_availability.sh.
Limitations of this script:
- Naming variations: Homebrew package names might be significantly different from the application bundle names.
- False positives/negatives: The simple name sanitization might lead to incorrect matches or miss potential ones.
- Manual review needed: You'll likely need to manually inspect the output to confirm if the Homebrew package is indeed the same application you have installed.
In case you are wondering, this script and the instructions were written with the help of an LLM coding GPT. I've tested it on several different Intel and Apple Silicon Macs with solid results.