I have a iMac and Macbook for work and another set for home. I end up getting a new one every couple of years so I end up re-setting up everything atleast couple of times a year. So I wrote a script to automate as much as possible: https://github.com/pathikrit/mac-setup-script/blob/master/setup.sh

The only problem with above script is that there is no way for me to pre-check if a brew or a brew-cask package is still valid e.g. I want to something like brew check foo to make sure that brew still knows about foo. How do I do that?

  • Are you proposing to list the missing packages? It might be simpler to just cycle over the list and create a report of the missing packages or parse the errors when you try to install something that's missing. Basically, what is the end scenario for this "check" being used?
    – bmike
    Dec 9, 2014 at 19:06
  • I want it to just print out invalid package names. I do it currently using a hack curl of github: github.com/pathikrit/mac-setup-script/commit/…
    – pathikrit
    Dec 9, 2014 at 19:47
  • Why not just attempt the install and report failure if the return code isn't 0? What does pre-determining get you that attempting to install and detecting failure doesn't?
    – Ian C.
    Dec 9, 2014 at 19:49
  • Usually package names get outdated or renamed (e.g. htop got renamed to htop-osx). I would rather fix them all and hit install and forget about it rather than fix failuers at end and edit script by commenting out passed ones and running again
    – pathikrit
    Dec 9, 2014 at 20:20

1 Answer 1


To get a list of invalid brew formulas:

#!/usr/bin/env bash
for formula in ${brews[@]}; do
    brew info ${formula} >/dev/null 2>&1 || echo ${formula}

To get a list of invalid casks:

#!/usr/bin/env bash
for cask in ${casks[@]}; do
    brew cask info ${cask} >/dev/null 2>&1 || echo ${cask}

(brews and casks are the arrays defined in your setup script.)

  • This does not work since info does a substring search. For example, you can have an invalid package name e.g. brew info htop would exit with code 0 but it actually won't work if you try to install it because the actual package name is htop-osx.
    – pathikrit
    Dec 9, 2014 at 20:22
  • 1
    @wrick No, brew install htop works just fine and installs htop-osx. There's an alias defined for htop: github.com/Homebrew/homebrew/blob/master/Library/Aliases/htop brew info htop works because of the aforementioned alias. If you try brew info hto then you would get an error. brew info doesn't do substring search; brew search (contrib) does.
    – 4ae1e1
    Dec 9, 2014 at 21:49

You must log in to answer this question.

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