This interactive script scans your /Applications and ~/Applications directories to list installed apps, allowing you to select one and view its version. It supports multiple searches and includes a built-in quit option for easy use.
Click to view script…
#!/bin/bash
# Interactive App Version Finder for macOS with multi-search capability
# Define directories to search for applications.
APP_DIRS=("/Applications" "$HOME/Applications")
# Initialize an array to store found apps.
apps=()
# Search for .app directories (non-recursive) in defined directories.
for dir in "${APP_DIRS[@]}"; do
if [ -d "$dir" ]; then
while IFS= read -r -d $'\0' app; do
apps+=("$app")
done < <(find "$dir" -maxdepth 1 -type d -name "*.app" -print0)
fi
done
# Check if any apps were found.
if [ ${#apps[@]} -eq 0 ]; then
echo "No applications found in ${APP_DIRS[*]}."
exit 1
fi
# Main interactive loop.
while true; do
echo ""
echo "Available Applications:"
for i in "${!apps[@]}"; do
echo "[$i] $(basename "${apps[$i]}")"
done
echo "[q] Quit"
read -p "Enter the number of the app to check its version (or 'q' to quit): " input
# Check for the quit option.
if [[ "$input" =~ ^[Qq]$ ]]; then
echo "Exiting."
exit 0
fi
# Validate input is a number and within range.
if ! [[ "$input" =~ ^[0-9]+$ ]] || [ "$input" -ge "${#apps[@]}" ]; then
echo "Invalid selection. Please try again."
continue
fi
APP_PATH="${apps[$input]}"
APP_NAME=$(basename "$APP_PATH" .app)
# Retrieve the version information from the app's Info.plist.
VERSION=$(defaults read "$APP_PATH/Contents/Info" CFBundleShortVersionString 2>/dev/null)
if [ -z "$VERSION" ]; then
echo "Version information not found for $APP_NAME."
else
echo "$APP_NAME version: $VERSION"
fi
echo ""
# Ask if the user wants to perform another search.
read -p "Do you want to search for another app? (y/n): " answer
if [[ ! "$answer" =~ ^[Yy]$ ]]; then
echo "Exiting."
exit 0
fi
done