DEV Community

Cover image for How To Install Mac App Store Apps From The Terminal
dev_neil_a
dev_neil_a

Posted on

How To Install Mac App Store Apps From The Terminal

Introduction

Hi there. In this article, I'll be going over how you can install apps from the Mac App Store using the command line.

This can be used to help automate the bulk installation of apps that you need to install from the Mac App Store when you setup a new or existing Mac.

YouTube Video

If you would prefer to see this article in video form, there is a YouTube video available below:

Requirements

Before you start, you will need to have Homebrew or MacPorts installed and updated as the tool that is needed is installed using either of these package managers.

If you don't have Homebrew installed, I have a link to an article here that goes over how to install it, along with some typical commands to use with it.

Also, you'll need to have admin rights to your Mac. This is because the apps will be installed into the Applications folder on your Mac, which requires admin rights to do so.

Finally, you will need to be logged into the Mac App Store before you can install anything from it. If you aren't logged in, open the Mac App Store from the Apple menu and login.

Install MAS

To be able to install apps from the Mac App Store, you will need to install a tool called mas, which is short for Mac App Store. To install mas using Homebrew, run:

brew install mas
Enter fullscreen mode Exit fullscreen mode

01

Show Currently Installed Mac App Store Apps

Once mas is installed, you check that it works by having it show all, if any, currently installed apps from the Mac App Store on your Mac. To do this, run:

mas list
Enter fullscreen mode Exit fullscreen mode

02

As you can see I have a few apps installed from the Mac App Store. I'll go over the output shortly as it's in the same format when searching for apps on the Mac App Store. Which takes use onto...

Searching For Apps

Searching for apps in the Mac App Store is easily done with mas. Take a tool that is often used by developers, that being Slack. To find it, run:

mas search "slack"
Enter fullscreen mode Exit fullscreen mode

03

If you want to search for other apps, just replace slack with the name of the app.

The search results will show anything that contains the word "slack" in the name.

The one at the top is usually the closest match to what you are looking for; then, anything containing slack, followed by whatever the Mac App Store wants to show you.

Why WhatsApp and Office apps are shown is likely due to them being productivity (same category apps) or recommended apps.

The results are split into three columns. The first column is the apps ID number in the store, followed by the name of the app and then the version number. Personally, I would like to have a column added to the results for the developers name to help identify the app I'm looking for more easily.

I know that the top one is the Slack app as I've searched for it before so I'll copy it's ID as that is how mas interacts with the app store for a given app.

Getting Information About an App

Now that I have the ID, the next step is to check if that app ID is what I'm looking for. To do that, run:

mas info 803453959
Enter fullscreen mode Exit fullscreen mode

04

The output indicates it's from Slack Technologies L.L.C, which is the one I'm looking for. It also shows the release date, minimum OS level that is supported, the size and a link to the store page.

Checking the Store Page

Now, you could take that store page link and paste it into a browser to double check or you can run:

mas open 803453959
Enter fullscreen mode Exit fullscreen mode

This will then open the Mac App Store and go to the page for Slack.

06

Now, let's install Slack. Or rather attempt to install it. I'll explain that statement in a moment.

Installing Apps

To install an app, in this case Slack, run:

mas install 803453959
Enter fullscreen mode Exit fullscreen mode

It will then ask for your password. This is the password for an admin account on your Mac, not your iCloud or Mac App Store password.

Now, instead of installing it, I got this prompt instead.

07

It indicates that because I haven't previously bought it (yes, it's a free app but you still have to go through a checkout process), I cannot redownload it.

What you would have to do instead, is go to the Mac App Store page for Slack and then click on Get to "buy it". For now, I'm not going to do that. Instead, I'm going to use another app that I have previously purchased called PCalc. It's a scientific calculator that has been around for what seems like forever. To install it, I'll run:

mas install 403504866
Enter fullscreen mode Exit fullscreen mode

08

It might ask for the admin password again.

With it installed, I'll open up the Applications folder and I'll run PCalc to check it works.

09

And it does.

10

Updating / Upgrading Apps

Next, to check if there are any updates for any other apps that were installed from the Mac App Store, run:

mas outdated
Enter fullscreen mode Exit fullscreen mode

11

In my case, I don't have any to update. If there were any, you can update them by running:

mas update
Enter fullscreen mode Exit fullscreen mode

Or

mas upgrade
Enter fullscreen mode Exit fullscreen mode

Both of these commands do the exact same thing. With there being no output, other than going to a new command prompt, there is nothing to update.

12

Uninstalling Apps

To uninstall an app, you can do so by running:

mas uninstall 403504866
Enter fullscreen mode Exit fullscreen mode

In this case, I uninstalled PCalc. If I check the Applications folder, it's no longer there.

13

Bulk Installing Apps

The last thing I want to cover is bulk installing apps. Unlike Homebrew where you can install multiple packages with one command, mas only allows for one app to be installed at a time. The same applies if you want to bulk uninstall apps as well.

If you want to automate the bulk installation of multiple apps, you can use a shell or Python script (or any language that can interact with the OS) to install them. Here's a quick example of a shell script I made earlier:

#!/bin/zsh

# Define an array with the app ID's and
# a comment for each with the app name:
appList=(
    820244930 # Flap Flap
    403504866 # PCalc
)

# Install apps in the appList array:
for i in ${appList[@]}; do
  mas install $i
done
Enter fullscreen mode Exit fullscreen mode

It's a simple for loop that takes each index in the appList array and runs mas install with that ID to install it.

If you wanted to uninstall apps instead, just change mas install $i to mas uninstall $i.

And that is how you can install and manage apps from the Mac App Store using the command line.

Thanks for reading and have a nice day!

Top comments (0)