0

I looked around for this and couldn't find it. Before venturing into coding it, I thought I'd ask…

I regularly update my mac via terminal with brew, macports, pip, yarn, etc. So I started reinstalling my apps via brew cask so they get regularly updated. It's pretty mechanical, and I'm sure there's a way to automate it. All it'd need to do is ls the apps in the Applications folder, compare it to the brew cask list, and brew cask --force install those not already there. A more rounded script would use brew search and ask the user to pick and confirm if results were ambivalent.

2 Answers 2

0

Sorted!

cd /Applications
brew cask list -1 > apps.txt
brew search --casks > casks.txt
for f in *.app do
    if grep -Fixq ${${f%.*}// /-} casks.txt && ! grep -Fixq ${${f%.*}// /-} apps.txt
        then HOMEBREW_NO_AUTO_UPDATE=1 brew cask install --force ${${f%.*}// /-}
    fi
done
0
0

I wrote this last night, hope it helps, Should be up on github soon.

The script is designed to help manage macOS applications installed on a system, particularly those that are available through Homebrew Cask. The main purpose of the script is to identify applications that are installed on the system but not managed by Homebrew Cask, and provide the user with an option to install those applications using Homebrew Cask.

#!/usr/bin/env bash


# Change the current directory to /Applications, where most macOS applications are installed
cd /Applications

# Generate two text files: apps.txt and casks.txt
# apps.txt contains a list of applications already installed using Homebrew Cask
# casks.txt contains a list of all available Homebrew Cask applications
brew list --cask > apps.txt
brew search --casks "" > casks.txt

# Iterate through all .app files in the /Applications directory
for f in *.app; do
    # Check if the application name is present in the casks.txt file (available through Homebrew Cask)
    # and not present in the apps.txt file (not currently installed using Homebrew Cask)
    if grep -Fixq "${${f%.*}// /-}" casks.txt && ! grep -Fixq "${${f%.*}// /-}" apps.txt; then
        # Assign the original file name to a variable
        original_file_name="$f"

        # Assign the Homebrew Cask-friendly application name to a variable
        brew_app_name="${${f%.*}// /-}"

        # Prompt the user to confirm the installation
        while true; do
          read -p "Do you want to install '$brew_app_name'? (y/n/b) " confirmation

          case "$confirmation" in
            [yY])
              echo "Installing '$brew_app_name'..."
              brew cask install --force "$brew_app_name"
              break
              ;;
            [nN])
              echo "Skipping installation of '$brew_app_name'."
              break
              ;;
            [bB])
              echo "Backing up '$original_file_name' to /Users/macuser/appbackups..."
              if [ ! -d "/Users/macuser/appbackups" ]; then
                echo "Creating /Users/macuser/appbackups directory..."
                mkdir -p "/Users/macuser/appbackups"
              fi
              mv "$original_file_name" "/Users/macuser/appbackups/$original_file_name"
              echo "Installing '$brew_app_name'..."
              HOMEBREW_NO_AUTO_UPDATE=1 brew cask install --force "$brew_app_name"
              break
              ;;
            *)
              echo "Invalid response. Please try again."
              continue
              ;;
          esac
        done
    fi
done

# Remove the temporary files
rm apps.txt casks.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .