How to use the command 'mas' (with examples)

How to use the command 'mas' (with examples)

  • Osx
  • December 17, 2024

The mas command-line interface is a powerful tool designed to work directly with the Mac App Store from your terminal or command line. By using mas, users can manage their applications without having to open the graphical App Store application. This is particularly useful for automation scripts, bulk updates, or developers who prefer command-line over GUI-based interactions. Whether it’s signing in, searching for apps, or managing updates, mas provides a range of functionalities that streamline app management on macOS.

Use case 1: Sign into the Mac App Store for the first time

Code:

mas signin "user@example.com"

Motivation:
Signing into the Mac App Store is the foundational step for managing app purchases and downloads. Whether you are setting up a new device or starting fresh after a software reset, logging in ensures all your purchases are synchronized and accessible. This command is essential for automating the initial setup process of a machine.

Explanation:

  • mas: The command itself, indicating the use of the Mac App Store CLI tool.
  • signin: A subcommand instructing mas to initiate the sign-in process.
  • "user@example.com": Replace this with your actual Apple ID email. It specifies the account you intend to log into for accessing the Mac App Store.

Example Output:

==> Signing in to Apple ID: user@example.com
Password: 

Upon successful entry of the password, the user will be logged in without visual confirmation beyond potential command line notifications.

Use case 2: Show all installed applications and their product identifiers

Code:

mas list

Motivation:
Keeping track of installed applications along with their product identifiers is crucial for managing updates or re-installations, especially for users with a large app library. This list can aid in creating scripts for automated updates or indicate which applications may need manual attention.

Explanation:

  • mas: Invokes the Mac App Store command-line tool.
  • list: A subcommand that prompts mas to list all currently installed applications along with their unique product identifiers on the specific Mac.

Example Output:

409183694 Keynote (10.3.5)
682658836 GarageBand (10.4.1)

This output displays the product id, app name, and version, providing a comprehensive view of what is installed.

Use case 3: Search for an application, displaying the price alongside the results

Code:

mas search "application" --price

Motivation:
Users often need to search the Mac App Store for applications while being mindful of cost, especially in budget-conscious environments like educational institutions or businesses. Including price information directly in the search results helps make informed purchasing decisions quickly.

Explanation:

  • mas: Executes the Mac App Store command-line tool.
  • search "application": Searches for apps matching the “application” keyword. Replace with the desired app name.
  • --price: An argument that appends the price information of the found applications to the output.

Example Output:

409203825 Numbers - $19.99
409183694 Keynote - $19.99

This output pairs app names with their prices, simplifying purchasing decisions.

Use case 4: Install or update an application using exact numeric ID

Code:

mas install 123456789

Motivation:
Knowing the exact numeric ID of an application allows for faster installations or updates, bypassing possible ambiguities in application names. This use case is helpful for system administrators managing multiple machines or apps.

Explanation:

  • mas: Initiates the command-line interface for the App Store.
  • install: A subcommand for installing or updating an application.
  • 123456789: This represents the unique product ID of the app to be installed or updated. Replace with actual IDs from a mas list or search.

Example Output:

==> Downloading Numbers
==> Installed Numbers

The feedback confirms the application has been successfully downloaded and installed.

Code:

mas lucky "search_term"

Motivation:
The lucky subcommand is akin to a quick install option, ideal when the top search result is a guaranteed or known choice, saving time in browsing through multiple entries. It is similar to a one-click install for the top hit of a search.

Explanation:

  • mas: Calls the Mac App Store CLI.
  • lucky: A special subcommand to instantly choose the first result from a search operation.
  • "search_term": The keyword used to search the App Store.

Example Output:

==> Installing 123456789 Sample App

Given that a match is found, mas lucky quickly proceeds with installing the leading app.

Use case 6: List all outdated apps with pending updates

Code:

mas outdated

Motivation:
Knowing which applications require updates is a fundamental part of system maintenance, enhancing security and performance. Frequent checks with mas outdated ensure that no crucial updates are missed, especially on systems where manually checking each app can be cumbersome.

Explanation:

  • mas: The command-line utility for the App Store.
  • outdated: Requests a list of apps that have updates available.

Example Output:

409203825 Numbers (10.3.5 -> 10.3.9)

This output clearly lists current and new version numbers, aiding in update prioritization.

Use case 7: Install all pending updates

Code:

mas upgrade

Motivation:
Keeping applications up-to-date is essential for leveraging new features, squashing bugs, and closing security vulnerabilities. Automated processes benefit from the mas upgrade command by ensuring all applications are updated concurrently to foster a more secure and smoother running system.

Explanation:

  • mas: Runs the App Store CLI.
  • upgrade: A command to install updates for all applications with pending updates.

Example Output:

Upgrading Numbers
Upgrading Keynote

This output confirms that mas has embarked on updating the enumerated applications.

Use case 8: Upgrade a specific application

Code:

mas upgrade "numeric_product_id"

Motivation:
At times, users may need to upgrade a particular application due to immediate requirement changes or testing needs. Targeted updates with the specific mas upgrade command can meet such situational demands without disturbing other apps.

Explanation:

  • mas: Commands the Mac App Store interface utility.
  • upgrade: Directs the focus to updating an individual application.
  • "numeric_product_id": Represents the product ID of the application needing updates. It should be swapped with the specific app’s numeric ID from the outdated list.

Example Output:

Upgrading 409203825 Numbers

The displayed message affirms the selected application is being updated.

Conclusion:

The mas CLI offers notable advantages for managing Mac App Store applications. Its versatility facilitates everything from individual updates to full-scale automation scripts for initial setups or regular maintenance, proving indispensable for developers, IT administrators, and power users alike. By mastering the use cases outlined above, users can maximize efficiency and enhance their workflow.

Tags :

Related Posts

How to Use the Command 'go vet' (with Examples)

How to Use the Command 'go vet' (with Examples)

The go vet command is a crucial tool for Go developers, designed to check Go source code and report any suspicious constructs.

Read More
How to Use the Command 'vipw' (with Examples)

How to Use the Command 'vipw' (with Examples)

vipw is a command-line utility designed for system administrators to safely edit the ‘/etc/passwd’ file, which contains user account information.

Read More
How to Use the Command 'xinput' (with examples)

How to Use the Command 'xinput' (with examples)

The xinput command is a versatile utility in Unix-like systems that allows users to interact with the input subsystem.

Read More