From d555f5c55f347477868720095821a9ea8d231eaa Mon Sep 17 00:00:00 2001 From: Cheong Yip Date: Sun, 3 Dec 2023 17:52:02 +1100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Mac=20App=20Store=20command?= =?UTF-8?q?=20line=20utility=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extended the functionality of the utilities shell script, utils.sh, to support commands from the Mac App Store using the 'mas' command line interface. New functions 'mas_install' and 'mas_install_with_confirmation' help automate the installation of MacOS apps. As a part of the change, certain apps which were previously noted to be manually installed from the Mac App Store are now automated in their respective scripts. This includes apps like "Kindle", "GoPro Player + ReelSteady", "Bandwidth+", "Be Focused - Pomodoro Timer", "Presentify - Screen Annotation", "EasyRes", "Magnet", "Itemido: Manage Home Inventory" and "Telephone - VoIP SIP softphone". This update helps the script manage a broader range of applications. Additionally, references to manual installation steps for these apps are removed from 'print_optional_manual_items.sh'. Aliases have been introduced to shorten commonly used 'mas' commands, included in the 'bash_aliases' file. Finally, included 'mas-cli.sh' in 'main.sh' for the installation of 'mas' itself. --- src/os/installs/macos/desktop_utilities.sh | 7 +++ src/os/installs/macos/main.sh | 1 + src/os/installs/macos/mas-cli.sh | 11 ++++ src/os/installs/macos/misc_tools.sh | 5 ++ src/os/installs/macos/office_tools.sh | 2 + src/os/installs/macos/utils.sh | 63 ++++++++++++++++++++++ src/os/installs/macos/video_tools.sh | 3 ++ src/os/print_optional_manual_items.sh | 10 +--- src/shell/macos/bash_aliases | 14 +++++ 9 files changed, 107 insertions(+), 9 deletions(-) create mode 100755 src/os/installs/macos/mas-cli.sh diff --git a/src/os/installs/macos/desktop_utilities.sh b/src/os/installs/macos/desktop_utilities.sh index 45f875417..b8af5378b 100755 --- a/src/os/installs/macos/desktop_utilities.sh +++ b/src/os/installs/macos/desktop_utilities.sh @@ -9,8 +9,15 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \ print_in_purple "\n Desktop Utilities\n\n" brew_install_with_confirmation "AppCleaner" "appcleaner" "--cask" +mas_install_with_confirmation "Bandwidth+" "490461369" +# https://xwavesoft.com/be-focused-pro-for-iphone-ipad-mac-os-x.html +mas_install_with_confirmation "Be Focused - Pomodoro Timer" "973134470" brew_install_with_confirmation "Cheatsheet" "cheatsheet" "--cask" brew_install_with_confirmation "DisplayLink USB Graphics Software" "displaylink" "--cask" +mas_install_with_confirmation "EasyRes" "688211836" +mas_install_with_confirmation "Magnet" "441258766" +# https://presentify.compzets.com/ +mas_install_with_confirmation "Presentify - Screen Annotation" "1507246666" brew_install_with_confirmation "Raycast" "raycast" "--cask" brew_install_with_confirmation "Silicon" "silicon" "--cask" brew_install_with_confirmation "Unarchiver" "the-unarchiver" "--cask" diff --git a/src/os/installs/macos/main.sh b/src/os/installs/macos/main.sh index 3a2cf5b3d..f4b8294e2 100755 --- a/src/os/installs/macos/main.sh +++ b/src/os/installs/macos/main.sh @@ -31,6 +31,7 @@ main() { ./xcode.sh ./rosetta_2.sh ./homebrew.sh + ./mas-cli.sh ./../bash.sh ./git.sh diff --git a/src/os/installs/macos/mas-cli.sh b/src/os/installs/macos/mas-cli.sh new file mode 100755 index 000000000..aa132714c --- /dev/null +++ b/src/os/installs/macos/mas-cli.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +cd "$(dirname "${BASH_SOURCE[0]}")" \ + && . "../../utils.sh" \ + && . "./utils.sh" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +print_in_purple "\n Mac App Store command line interface\n\n" + +brew_install "mas-cli" "mas" diff --git a/src/os/installs/macos/misc_tools.sh b/src/os/installs/macos/misc_tools.sh index 1e4b7f111..b4f0f2dca 100755 --- a/src/os/installs/macos/misc_tools.sh +++ b/src/os/installs/macos/misc_tools.sh @@ -8,4 +8,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \ print_in_purple "\n Miscellaneous Tools\n\n" +# https://www.itemido.com/en/index.html +mas_install_with_confirmation "Itemido: Manage Home Inventory" "1552953842" # brew_install_with_confirmation "Keybase" "keybase" "--cask" +# https://www.64characters.com/telephone/ +# https://github.com/64characters/Telephone +mas_install_with_confirmation "Telephone - VoIP SIP softphone" "406825478" diff --git a/src/os/installs/macos/office_tools.sh b/src/os/installs/macos/office_tools.sh index 2f40bf75a..e0cf9962f 100755 --- a/src/os/installs/macos/office_tools.sh +++ b/src/os/installs/macos/office_tools.sh @@ -10,6 +10,8 @@ print_in_purple "\n Office Tools\n\n" brew_install_with_confirmation "Dropbox" "dropbox" "--cask" brew_install_with_confirmation "Calibre" "calibre" "--cask" +# Rename registered device within Amazon https://www.amazon.com.au/hz/mycd/digital-console/alldevices +mas_install_with_confirmation "Kindle" "302584613" brew_install_with_confirmation "Notion" "notion" "--cask" brew_install_with_confirmation "PDF Expert" "pdf-expert" "--cask" brew_install_with_confirmation "Microsoft Office" "microsoft-office" "--cask" diff --git a/src/os/installs/macos/utils.sh b/src/os/installs/macos/utils.sh index 3c76c8db6..e1be647bf 100755 --- a/src/os/installs/macos/utils.sh +++ b/src/os/installs/macos/utils.sh @@ -119,3 +119,66 @@ brew_upgrade() { "Homebrew (upgrade)" } + +mas_install() { + + declare -r APP_STORE_READABLE_NAME="$1" + declare -r APP_STORE_IDENTIFIER="$2" + + # If environment variable is set and readable name does not match regex, then exit and don't bother installation + if [[ -n "$INSTALL_APPLICATION_IF_READABLE_NAME_MATCH_REGEX" && ! "$APP_STORE_READABLE_NAME" =~ $INSTALL_APPLICATION_IF_READABLE_NAME_MATCH_REGEX ]]; then + print_warning "$APP_STORE_READABLE_NAME not installed as readable name did not match regex: \"$INSTALL_APPLICATION_IF_READABLE_NAME_MATCH_REGEX\"" + return 1 + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Check if `Mac App Store command line interface` is installed. + + if ! cmd_exists "mas"; then + print_error "$APP_STORE_READABLE_NAME ('Mac App Store command line interface' is not installed)" + return 1 + fi + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + # Install the specified formula. + + + execute \ + "mas install $APP_STORE_IDENTIFIER" \ + "$APP_STORE_READABLE_NAME (https://apps.apple.com/au/app/id$APP_STORE_IDENTIFIER)" + +} + +mas_install_with_confirmation() { + + declare -r APP_STORE_READABLE_NAME="$1" + declare -r APP_STORE_IDENTIFIER="$2" + declare -r APP_STORE_NAME_WITH_LINK="$APP_STORE_READABLE_NAME (https://apps.apple.com/au/app/id$APP_STORE_IDENTIFIER)" + + # Install application if previous confirmation reply was 'install all' + if [[ "$previousInstallApplicationConfirmationReply" =~ ^[aA]$ ]]; then + mas_install "$@" + # DON'T install application if previous confirmation reply was 'skip all' + elif [[ "$previousInstallApplicationConfirmationReply" =~ ^[sS]$ ]]; then + print_warning "$APP_STORE_NAME_WITH_LINK (not installed)" + # Otherwise, prompt user and install application based on reply + else + local installApplicationConfirmationReply="" + # Until a valid reply has been entered, keep prompting user + while [[ -z "$installApplicationConfirmationReply" || "$installApplicationConfirmationReply" =~ ^[^yYnNaAsS]$ ]]; do + ask_for_install_application_confirmation "Do you want to install $APP_STORE_NAME_WITH_LINK?" + installApplicationConfirmationReply="$(get_answer)" + done + + if answer_is_yes || answer_is_yes_to_all; then + mas_install "$@" + elif answer_is_no || answer_is_skip_all; then + print_warning "$APP_STORE_NAME_WITH_LINK (not installed)" + fi + + previousInstallApplicationConfirmationReply="$(get_answer)" + fi + +} diff --git a/src/os/installs/macos/video_tools.sh b/src/os/installs/macos/video_tools.sh index 53280a016..a517c22ee 100755 --- a/src/os/installs/macos/video_tools.sh +++ b/src/os/installs/macos/video_tools.sh @@ -11,6 +11,9 @@ print_in_purple "\n Video Tools\n\n" brew_install_with_confirmation "VLC" "vlc" "--cask" brew_install_with_confirmation "FFmpeg" "ffmpeg" +# https://gopro.com/en/au/shop/quik-app-video-photo-editor +# https://gopro.com/en/au/info/gopro-player +mas_install_with_confirmation "GoPro Player + ReelSteady" "1460836908" brew_install_with_confirmation "Handbrake" "handbrake" "--cask" diff --git a/src/os/print_optional_manual_items.sh b/src/os/print_optional_manual_items.sh index 930965bb5..01e78d94f 100755 --- a/src/os/print_optional_manual_items.sh +++ b/src/os/print_optional_manual_items.sh @@ -41,18 +41,11 @@ main() { print_optional_info "Assess Unity (https://unity.com/)" print_in_purple "\n Desktop Utilities\n\n" - print_optional_info "Install Magnet from App Store (https://itunes.apple.com/au/app/magnet/id441258766?mt=12)" - print_optional_info "Install Bandwidth+ from App Store (https://itunes.apple.com/au/app/bandwidth/id490461369?mt=12)" - print_optional_info "Install Be Focused from App Store (https://apps.apple.com/au/app/be-focused-pomodoro-timer/id973134470?mt=12 | https://xwavesoft.com/be-focused-pro-for-iphone-ipad-mac-os-x.html)" - print_optional_info "Install Presentify from App Store (https://apps.apple.com/app/id1507246666 and https://presentify.compzets.com/)" - print_optional_info "Install EasyRes from App Store (https://itunes.apple.com/au/app/easyres/id688211836?mt=12)" print_optional_info "Install XtraFinder (http://www.trankynam.com/xtrafinder/) + setup preferences at src/os/preferences/macos/xtrafinder.sh" print_in_purple "\n Miscellaneous Tools\n\n" print_optional_info "Install Keybase" print_optional_info "Install Ledger Live (https://www.ledger.com/pages/ledger-live or 'brew install --cask ledger-live')" - print_optional_info "Install Telephone - VoIP SIP softphone (https://apps.apple.com/us/app/telephone/id406825478 and https://www.64characters.com/telephone/ and https://github.com/64characters/Telephone)" - print_optional_info "Install Itemido: Manage Home Inventory from App Store (https://apps.apple.com/us/app/itemido-manage-home-inventory/id1552953842 and https://www.itemido.com/en/index.html)" print_optional_info "Assess Rewind (https://www.rewind.ai/)" print_in_purple "\n Remote Access Tools\n\n" @@ -60,14 +53,13 @@ main() { print_optional_info "Assess TeamViewer (https://www.teamviewer.com/)" print_in_purple "\n Office Tools\n\n" - print_optional_info "Install Kindle from App Store (https://apps.apple.com/us/app/amazon-kindle/id302584613) and rename registered device within Amazon https://www.amazon.com.au/hz/mycd/digital-console/alldevices" print_optional_info "Install Evernote (archive of old notes - use webapp)" + print_optional_info "Rename registered Kindle device within Amazon https://www.amazon.com.au/hz/mycd/digital-console/alldevices" print_optional_info "Assess Liquitext (https://www.liquidtext.net/)" print_optional_info "Assess Logseq (https://logseq.com/)" print_in_purple "\n Video Tools\n\n" print_optional_info "Install Spatial Media Metadata Injector (https://github.com/google/spatial-media/releases and https://github.com/google/spatial-media/issues/261#issuecomment-1590148367)" - print_optional_info "Install GoPro Player + ReelSteady from App Store (https://apps.apple.com/us/app/gopro-player/id1460836908?ls=1&mt=12 and https://gopro.com/en/au/info/gopro-player)" print_optional_info "Install Blackvue Viewer for Mac (https://www.blackvue.com/download/blackvue-mac-viewer-cloud/)" print_in_purple "\n Virtualisation Tools\n\n" diff --git a/src/shell/macos/bash_aliases b/src/shell/macos/bash_aliases index be939c7ff..9bfe8c6e2 100644 --- a/src/shell/macos/bash_aliases +++ b/src/shell/macos/bash_aliases @@ -46,6 +46,19 @@ alias brew-bundle-read-dump='brew bundle install --file=$HOME/.dotfiles/src/os/i # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Shorter commands for `Mac App Store command line interface`. + +# https://github.com/mas-cli/mas +# https://github.com/mas-cli/mas/tree/main/Sources/MasKit/Commands +alias maso="mas outdated" +alias masi="mas install" +alias masr="mas uninstall" +alias mass="mas search" +alias masl="mas list" +alias masu="mas upgrade" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # Clear DNS cache. alias clear-dns-cache="sudo dscacheutil -flushcache; \ @@ -109,6 +122,7 @@ alias u="sudo softwareupdate --install --all \ && brew upgrade \ && brew-upgrade-casks \ && brew cleanup \ + && mas upgrade \ && bash-it update \ && upgrade-jenv \ && sdk selfupdate \