Brew based reinstall script for macOS

Reinstall Script for macOS

macOS is shipped with a very powerful shell, allowing you to use command line whenever needed.

When you have to install an app from Internet, what do you do: search for it, download it, open DMG file, copy to Applications folder, unmount DMG and trash it. How boring!

I have thus created a tiny script that automates all of these actions. You will find it on my personal repository.

This tiny script is an example of how command line can make your life easier. It relies on Brew to install everything you need the easy way.

How to use it

Although this script is given as-is as an example of what you can do with Brew, it is not really meant to fit your needs. In fact, it’s made to fit my needs, as I use it to reinstall all my apps at once when I reset my Mac.

So what I advise you to do is the following:

  • create an .sh file containing only “#!/bin/bash”. This is mandatory and will tell the system that this file is a shell script.
  • launch terminal, cd to the file’s directory and type “chmod +x”. This will make it executable.
  • insert after the “#!/bin/bash” all the commands you need.
  • launch your script and watch the magic happen.

Installing stuff from the mac AppStore

brew, as-is, cannot handle mac AppStore apps. Fortunately, Mas come to the rescue. I strongly advise you to read its Gihub presentation to understand how to easily install AppStore apps from mas.

For example, Xcode. I use this command:

Here’s how I composed it. First,

searches for “xcode” in the AppStore. It will return a great amount of results, but only XCode (the first result) interests us. So I trim the result to the first line:

In this first line, we need to retrieve the app code, so we trim the first line to its first word (which is actually a number):

Then, we pass the result (the app code) to “mas install”:

Tada, you’re done. BTW: mas will ask you for your AppStore credentials when needed, so it is a good idea to group all of your mas installation to avoid typing these credentials more than once.

Changing OSX parameters.

Many parameters can be changed from command line using AppleScripts. Unfortunately, there is no way to know how to change a given parameter but by browsing the web for a nice and clever solution.

Anyway, to launch a piece of AppleScript, use this command:

AppleScript is very, very, very powerful, almost as powerful as shell is. However, this is not my strong suit, so all I can tell you is to search the web for the magical command you need, adapt it, embed it to your scripts. In my example, I needed a command to automatically setup dock autohide.

Customizing the dock

K. Crawford has created a nifty little tool called dockutil that allows you to customize your Dock from the command line. I use it in this script to clean mine from unwanted icons.


This scripts comes under do-whatever-you-want-to-do licence. Have fun!