Skip to content

Instantly share code, notes, and snippets.

@planetoid
Created December 5, 2024 14:40
Show Gist options
  • Save planetoid/7028f19cd80f45af86f0ebc13b3fe2e8 to your computer and use it in GitHub Desktop.
Save planetoid/7028f19cd80f45af86f0ebc13b3fe2e8 to your computer and use it in GitHub Desktop.
Edge Version Cleaner
#!/bin/bash
#===========================================
# Edge Version Cleaner
#===========================================
# Functions:
# - Display current versions of Microsoft Edge Stable and Edge Dev
# - List installed versions in msedge-stable & msedge-dev directories
# - Identify and move old versions to Trash
# - Single confirmation step to delete all old versions
#
# Usage:
# chmod +x edge-cleanup.sh
# ./edge-cleanup.sh
#
# Purpose:
# Clean up old Edge browser versions to free up disk space
#===========================================
# Check and get Edge versions
EDGE_STABLE_PATH="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
EDGE_DEV_PATH="/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"
ALL_DIRS_TO_DELETE=()
ALL_PATHS_TO_DELETE=()
check_edge() {
local path=$1
local name=$2
local dir=$3
if [ -f "$path" ]; then
local version=$("$path" --version | awk '{print $3}')
echo -e "\n=== $name ==="
echo "► Current version: $version"
echo -e "\n► Installed versions in $dir:"
ls "$dir"
echo -e "\n► Old versions detected:"
while IFS= read -r dir_name; do
if [ "$dir_name" != "$version" ]; then
echo "- $dir_name"
ALL_DIRS_TO_DELETE+=("$name: $dir_name")
ALL_PATHS_TO_DELETE+=("$dir/$dir_name")
fi
done < <(ls "$dir")
else
echo -e "\n=== $name ==="
echo "❌ Not installed: $path"
fi
}
# Process Edge Stable
check_edge "$EDGE_STABLE_PATH" "Microsoft Edge" "$HOME/Library/Application Support/Microsoft/EdgeUpdater/apps/msedge-stable"
check_edge "$EDGE_DEV_PATH" "Microsoft Edge Dev" "$HOME/Library/Application Support/Microsoft/EdgeUpdater/apps/msedge-dev"
# Unified deletion confirmation
if [ ${#ALL_DIRS_TO_DELETE[@]} -eq 0 ]; then
echo -e "\n✓ No old versions found to delete."
exit 0
fi
echo -e "\n=== Summary of versions to delete ==="
printf '%s\n' "${ALL_DIRS_TO_DELETE[@]}"
read -p $'\n'"Delete these versions? (Y/n): " confirm
if [[ $confirm == [Yy]* || $confirm == "" ]]; then
for full_path in "${ALL_PATHS_TO_DELETE[@]}"; do
if [ -d "$full_path" ]; then
osascript -e "tell application \"Finder\" to delete POSIX file \"$full_path\"" >/dev/null
echo "🗑️ Moved to Trash: $(basename "$full_path")"
fi
done
echo -e "\n✅ Cleanup complete!"
else
echo -e "\n⚠️ Operation cancelled."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment