Skip to content

Instantly share code, notes, and snippets.

Last active September 15, 2022 11:30
  • Star 61 You must be signed in to star a gist
  • Fork 27 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Script upgrading outdated brew casks
#!/usr/bin/env bash
(set -x; brew update;)
(set -x; brew cleanup;)
(set -x; brew cask cleanup;)
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
casks=( $(brew cask list) )
for cask in ${casks[@]}
version=$(brew cask info $cask | sed -n "s/$cask:\ \(.*\)/\1/p")
installed=$(find "/usr/local/Caskroom/$cask" -type d -maxdepth 1 -maxdepth 1 -name "$version")
if [[ -z $installed ]]; then
echo "${red}${cask}${reset} requires ${red}update${reset}."
(set -x; brew cask uninstall $cask --force;)
(set -x; brew cask install $cask --force;)
echo "${red}${cask}${reset} is ${green}up-to-date${reset}."
Copy link

atais commented May 3, 2016

Copy link

Brilliant, thank you 👍

Copy link

This is sweet! Thanks!

Copy link

hideout commented Jun 4, 2016

thanks atais for that script!
that is what i was searching ...


Copy link

mshick commented Aug 2, 2016

Great script. Much appreciated.

Copy link

gasperz commented Sep 2, 2016

It looks like it stopped working. I know it was working before but now it is not working for my anymore. When I run it everything looks ok. I get no errors.
But I can see that there is new version of cask. for example brew cask info brave gets me newer version than the one installed. But it isn't upgraded. I also tried with brew cask list | xargs brew cask install --force and with this, it gets upgraded.

Copy link

gasperz commented Sep 8, 2016

I made small change and it work again. I changed line 16 to installed="$(brew cask info $cask | grep 'does not exist')"
My gist

Copy link

atais commented Sep 10, 2016

@gasperz I am not sure if that is enough. Current output for brew cask info iterm2

iterm2: 3.0.8
/usr/local/Caskroom/iterm2/3.0.5 (68B)
==> Name
==> Artifacts (app)
iterm2 is up-to-date.

seems that my version is outdated, but...
I can not see any string determining if version is installed here... and finding it out other way will be more complex.

Copy link

I've just created a slightly modified version of this script and it seems to do the trick for me:

Additionally it also updates regular brew packages, not only the cask ones.

Copy link

gasperz commented Sep 14, 2016

@atais You are correct. It was my mistake. but @jwadolowski solution does work for me. Tested with VirtualBox cask.

Copy link

atais commented Sep 19, 2016

Well in the meantime I have raised a question on brew cask github: Homebrew/homebrew-cask#24412

And got an interesting link:
Have not tried yet.

Copy link

atais commented Sep 21, 2016

@jwadolowski I have merged your changes to my gist. Thanks!

Copy link

hao-lh commented Jan 21, 2017

There might be an issue with uninstalling the app first, since the download might fail if the network connection is bad, recommending remove the code on L21 since install with --force option would overwrite its ancestor by default.

Copy link

It is awesome!


Copy link

maxisme commented Oct 19, 2017

Thank you!

Copy link

This is unfortunately outdated.
Brew no longer uses cask. Now It's brew install --cask instead of brew cask install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment