Mac App Store 的简单命令行界面 mas 专为脚本和自动化而设计

9 min read
brew install mas

要首次登录 Mac App Store,请运行 mas signin

$ mas signin [email protected]
==> Signing in to Apple ID: [email protected]
Password:

您还可以在命令中嵌入密码。

$ mas signin [email protected] 'ZdkM4f$gzF;gX3ABXNLf8KcCt.x.np'
==> Signing in to Apple ID: [email protected]

Mac App Store 中的每个应用程序都有一个产品标识符,该标识符也用于 mas-cli 命令。使用 mas list 将显示所有已安装的应用程序及其产品标识符。

$ mas list
446107677 Screens
407963104 Pixelmator
497799835 Xcode

可以使用 mas search 按名称搜索应用程序,这将搜索 Mac App Store 并返回匹配的标识符。包含 --price 标志以在结果中包含价格。

$ mas search Xcode
497799835 Xcode
688199928 Docs for Xcode
449589707 Dash 3 - API Docs & Snippets. Integrates with Xcode, Alfred, TextWrangler and many more.
[...]

另一种查找应用程序标识符的方法是

  1. 在 Mac App Store 中查找应用程序
  2. 选择 Share > Copy Link
  3. 从字符串中获取标识符,例如对于 Xcode, https://apps.apple.com/us/app/xcode/id497799835?mt=12 具有标识符 497799835

要安装或更新应用程序,只需使用应用程序标识符运行 mas install

$ mas install 808809998
==> Downloading PaintCode 2
==> Installed PaintCode 2

要安装所有挂起的更新,请运行 mas upgrade

$ mas upgrade
Upgrading 2 outdated applications:
Xcode (7.0), Screens VNC - Access Your Computer From Anywhere (3.6.7)
==> Downloading Xcode
==> Installed Xcode
==> Downloading iFlicks
==> Installed iFlicks