6

I am trying to install some softwares using brew cask and I would like to check if the package/formula is already installed through brew or other means

I have a script that installs a list of softwares using brew cask and I dont want it to install a software that is already present on the machine

To achive this I referred to this question: With Homebrew, how to check if a software/package is installed?

This is pointed me in the right direction but I can only avoid installing software that is installed via brew cask.

If the software is installed by downloading the dmg and is already present in the /Applications/ folder then it does not recognize that and it continues to install the software.

Is there a way to figure out if the application is installed via brew or any other means before my script starts installing it

7
  • "If the software is installed by downloading the dmg and is already present in the /Applications/ folder then it does not recognize that and it continues to install the software." Use find command to search the /Applications and ~/Applications folder for the target formula. List out all the matches in the console and ask user if they want to continue install or not.
    – anki
    Commented Sep 10, 2020 at 5:00
  • @anki But the formula name and the Application name are not the same. For e.g. google chrome formula is google-chrome while the application name is 'Google Chrome' In this scenario I will have to keep on editing the script if the app decides to change its name.
    – Nick Div
    Commented Sep 10, 2020 at 5:27
  • regex, case insensitive search etc can be helpful here. I don't know any central list of all installed apps. You just have to search..
    – anki
    Commented Sep 10, 2020 at 5:29
  • @anki I guess. I was hoping there was some way I could have extracted the app name from formula by brew before installing but it seems i do not have any other option.
    – Nick Div
    Commented Sep 10, 2020 at 5:32
  • 1
    You could parse the output of brew cask info --json=v1 google-chrome or brew cask info google-chrome to find the name the cask will install to. It won't help in case of renamed applications though.
    – nohillside
    Commented Sep 10, 2020 at 6:11

2 Answers 2

4

I assume you know the name of the application. Then just test for existence of the application

if [[ ! -d "/Applications/APP-TO-CHECK.app" ]]; then
    # install APP-TO-CHECK
fi 
5
  • But the formula name and the Application name are not the same. For e.g. google chrome formula is google-chrome while the application name is 'Google Chrome' In this scenario I will have to keep on editing the script if the app decides to change its name.
    – Nick Div
    Commented Sep 10, 2020 at 5:27
  • I tried to run your script but it gives me the following error: syntax error in conditional expression -> if [[ ! -d /Applications/Google Chrome.app ]]; then
    – Nick Div
    Commented Sep 10, 2020 at 5:33
  • Adding quotes to it fixed the issue
    – Nick Div
    Commented Sep 10, 2020 at 5:35
  • 1
    @NickDiv Names with spaces always need to be quoted in the shell. As for the renaming issue: I don‘t see a failsafe way to cover all possible scenarios, and honestly consider this to be rare. If necessary I would just test for all known names.
    – nohillside
    Commented Sep 10, 2020 at 5:50
  • That's the POSIX standard for test. It's sufficient to write [ and ]. This works in any shell. There is no need for [[ and ]]. See BashFAQ/031: mywiki.wooledge.org/BashFAQ/031 Commented Sep 14, 2020 at 19:22
1

This is a primitive solution but it might help.

  1. Download this app (it allows you to search hidden files.)
  2. Search for the name of your application/repo you want to download.
  3. If it is not there, then it is safe to say you don't have it.

You must log in to answer this question.

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