mas CLI

repository·main·Indexed 11 days ago

https://github.com/mas-cli/mas

A command-line interface for the Mac App Store designed for scripting and automation. It allows developers to search, install, update, and manage Mac App Store applications via the terminal using ADAM IDs or Bundle IDs. Features include JSON output for programmatic access, integration with Homebrew Bundle and Topgrade, and tools for managing app updates with configurable accuracy modes.

Tokens
6.4K
Snippets
39
Records
43
Agent score
95%

What's inside mas

  1. Integrations for mas CLI

    main

    The mas CLI can be integrated with other automation tools:

    • Homebrew Bundle: Use mas to include installed apps in a Brewfile. You can then use brew bundle to get, install, and update apps listed in the Brewfile.
    • Topgrade: Use topgrade to automate the updating of your apps via mas.
  2. Understand root privileges and Apple Account requirements

    main

    Root Privileges

    Commands that modify the system (get, install, lucky, update, uninstall) require root privileges. mas will request them via sudo as necessary. It uses existing valid sudo credentials or prompts for the macOS user password. The password is never stored by mas.

    Apple Account Requirements

    Commands that interact with the App Store (get, install, lucky, update, and outdated --accurate) require an Apple Account to be signed in to the App Store.

    Authentication behavior depends on System Settings:

    • If 'Use Touch ID for purchases...' is Enabled: You must authenticate (Touch ID or password) for each app being processed.
    • If 'Use Touch ID for purchases...' is Disabled: Behavior depends on the 'Free Downloads' setting:
      • Always Require: Authentication required for every app.
      • Never Require: Apps are processed without additional authentication.
  3. Configure outdated-app detection (Accuracy and macOS compatibility)

    main

    When running outdated or update, you can control how mas determines if an app needs an update using two main concepts: Minimum macOS Check and Accuracy.

    Minimum macOS Check

    • --check-min-os (default): Only reports apps as outdated if the latest version is compatible with your current macOS.
    • --no-check-min-os: Reports an app as outdated even if the latest version is incompatible with your current macOS. This prevents false negatives but may cause false positives.

    Accuracy Modes

    Select between these two mutually exclusive modes:

    FlagMethodProsCons
    --inaccurate (default)Queries iTunes Search APIFast (~7ms/app), no hangs, no dialogsPotential false positives/negatives due to API lag or inconsistent version reporting
    --accurateInitiates a metadata download100% accurateSlow (~175ms/app), can hang if checking 100+ apps, requires Apple Account, may show dialogs

    Note on --accurate: In outdated mode, the download is immediately cancelled after reading metadata. In update mode, the download is only cancelled if the version matches the installed version; otherwise, the update proceeds.

    # Check for outdated apps accurately
    mas outdated --accurate
  4. Identify App IDs (ADAM ID vs Bundle ID)

    main

    App Store apps are identified by two unique types of IDs. mas commands accept both as arguments:

    • ADAM ID: An integer (e.g., 497799835). By default, mas treats all-digit arguments as ADAM IDs.
    • Bundle ID: A string (e.g., com.apple.dt.Xcode).

    To force an all-digit ID to be treated as a Bundle ID, use the --bundle flag.

    How to find an ADAM ID:

    1. Use mas search <term> or mas list.
    2. Extract it from an App Store URL (e.g., in https://apps.apple.com/us/app/xcode/id497799835?mt=12, the ID is 497799835).
    # Example: Using a Bundle ID explicitly if it looks like an ADAM ID
    mas install --bundle 123456789
  5. Install mas CLI

    main

    You can install mas using several package managers depending on your macOS version and preference:

    • Homebrew Core (Recommended for macOS 14+): brew install mas
    • Homebrew Tap (For macOS 13+): brew install mas-cli/tap/mas
    • MacPorts (For macOS 13+): sudo port install mas
    • GitHub Releases: Download installers or source archives directly from the releases page.
    # Using Homebrew Core
    brew install mas
    
    # Using Homebrew Tap
    brew install mas-cli/tap/mas
    
    # Using MacPorts
    sudo port install mas
  6. Use the mas CLI

    main

    The mas command-line interface provides a way to interact with the Mac App Store from the terminal. It supports a wide range of subcommands for managing applications, including installation, updates, searching, and configuration.

    To see the full list of available commands, run mas --help.

    # Example: list installed apps
    mas list
    
    # Example: search for an app
    mas search "Xcode"
  7. Troubleshoot Spotlight indexing for installed apps

    main

    Commands like list, outdated, get, install, lucky, update, and uninstall rely on the Spotlight Metadata Service (MDS) to find installed apps. If an app is not appearing in mas results, it may not be indexed in Spotlight.

    1. Verify if an app is indexed: Use mdls to check for the kMDItemAppStoreAdamID attribute:

    mdls -rn kMDItemAppStoreAdamID /Applications/Xcode.app

    If it outputs nothing, the app is not indexed.

    2. Find an app path via ADAM ID:

    mdfind 'kMDItemAppStoreAdamID = <adam-id>'

    3. Fix indexing:

    • Individual app: mdimport /Applications/Xcode.app
    • All apps on primary volume:
      vol="$(/usr/libexec/PlistBuddy -c "Print :PreferredVolume:name" ~/Library/Preferences/com.apple.appstored.plist 2>/dev/null)"
      mdimport /Applications "${vol:+"/Volumes/${vol}/Applications"}"
    • All volumes: sudo mdutil -Eai on
    # Check if Xcode is indexed
    mdls -rn kMDItemAppStoreAdamID /Applications/Xcode.app
  8. Troubleshoot mas CLI issues

    main

    Common issues and their solutions:

    • Managing system software (macOS, Safari, etc.): mas does not manage system software. Use the softwareupdate command instead.
    • Inconsistent app data: The App Store uses eventual consistency. You may need to wait hours or days for data to synchronize.
    • Cannot purchase paid apps: Purchase paid apps directly within the Mac App Store.
    • iOS & iPadOS apps: These are currently unsupported.
    • Hangs or Undetected installed apps: Try indexing your apps in Spotlight. If hangs persist, report a bug.
    • 'This redownload is not available for this Apple Account...' error: Ensure you are signed in to the correct Apple Account in the App Store, or uninstall the app and re-acquire it using the current account.
    • Paid apps purchase errors: If you encounter issues purchasing paid apps via CLI, purchase them directly in the App Store.
  9. Reference: mas CLI commands

    main

    The mas CLI provides a variety of commands for interacting with the Mac App Store. For detailed documentation, use man mas or mas --help in your terminal.

    | Command | Functionality | Aliases |

    search <term>…              | Search for App Store apps
    lookup <id>…                | Output App Store app details | info
    list [<id>…]                | Output installed apps
    outdated [<id>…]           | Output outdated apps
    outdated --accurate [<id>…] | Output outdated apps
    get <id>…                   | Get free apps, install any apps | purchase
    install <id>…               | Install gotten or purchased apps
    lucky <term>…               | Install first matching app
    update [<id>…]              | Update outdated apps | upgrade
    update --accurate [<id>…]    | Update outdated apps | upgrade
    uninstall (<id>…|--all)     | Uninstall apps
    signout                     | Sign out from App Store
    open [<id>]                 | Open app App Store page
    home <id>…                  | Open app web pages
    seller <id>…                | Open seller app web pages | vendor
    reset                       | Reset App Store processes
    config                      | Output config
    version                     | Output version
  10. Output data as JSON

    main

    By default, mas commands output tabular data or key-value pairs. To use mas in scripts or for programmatic access, use the --json flag to output a stream of JSON objects.

    • list, outdated, & search: Output a stream of JSON objects (one per app) containing all fields provided by Apple. Keys are mapped to more readable names and are sorted numerically.
    • config: Outputs all settings in a single JSON object.
    • lookup: When --json is supplied, it outputs a JSON object for the app.
    # Example: List outdated apps in JSON format
    mas outdated --json
  11. Troubleshoot 'No installed apps found' when using mas list

    main

    If mas list returns no results but you know apps are installed, you may need to re-index your applications using Spotlight (mdimport).

    To index a specific app (e.g., Xcode):

    mdimport /Applications/Xcode.app

    To index all applications on your main volume:

    vol="$(/usr/libexec/PlistBuddy -c "Print :PreferredVolume:name" ~/Library/Preferences/com.apple.appstored.plist 2>/dev/null)"
    mdimport /Applications ${vol:+"/Volumes/${vol}/Applications"}

    To ensure Spotlight indexing is enabled for all volumes:

    sudo mdutil -Eai on
    # Example: Indexing a specific app
    mdimport /Applications/Xcode.app
  12. JSON output schema for `mas config`

    main

    When requested in JSON format, the mas config command returns an object containing the following keys:

    KeyDescription
    masThe version of mas
    sliceThe architecture of the currently running slice
    slicesA space-separated list of supported slice architectures
    distThe distribution
    originThe git origin
    revThe git revision
    swiftThe Swift version
    driverThe Swift driver version
    storeThe App Store region
    regionThe macOS region
    macosThe macOS version (major.minor.patch)
    buildThe macOS build version (from kern.osversion)
    macThe hardware product name (from hw.product)
    cpuThe CPU brand string (from machdep.cpu.brand_string)
    archThe hardware machine architecture (from hw.machine)
    {
      "mas": "7.0.0",
      "slice": "arm64",
      "slices": "arm64 x86_64",
      "dist": "...",
      "origin": "...",
      "rev": "...",
      "swift": "...",
      "driver": "...",
      "store": "...",
      "region": "...",
      "macos": "14.4.0",
      "build": "...",
      "mac": "...",
      "cpu": "...",
      "arch": "arm64"
    }