Skip to content

Instantly share code, notes, and snippets.

@solrevdev
Last active January 15, 2022 14:26
Show Gist options
  • Save solrevdev/59704b0249e401ac048a01231908d6e0 to your computer and use it in GitHub Desktop.
Save solrevdev/59704b0249e401ac048a01231908d6e0 to your computer and use it in GitHub Desktop.
Uses the macupdater_client (https://www.corecode.io/macupdater/enterprise.html) and jq to update macOS app from the command line
#!/usr/bin/env bash
pc=$(hostname)
echo "macupdater 2 pro command line via $pc on $(date +"%Y-%m-%d %T")"
echo '--------------------------------------------------------------'
echo ''
echo ''
echo 'checking for prerequisites...'
echo '[] jq'
echo '[] /Applications/MacUpdater.app/Contents/Resources/macupdater_client'
if ! command -v jq &>/dev/null; then
echo 'jq could not be found'
echo 'please install jq from https://stedolan.github.io/jq/'
exit 1
fi
macupdater_file=/Applications/MacUpdater.app/Contents/Resources/macupdater_client
if [ ! -f "$macupdater_file" ]; then
echo "$macupdater_file does not exist..please install macupdater_client via macupdater 2 website"
echo 'you can also alias macupdater_client to [/Applications/MacUpdater.app/Contents/Resources/macupdater_client]'
echo 'https://www.corecode.io/macupdater/enterprise.html'
exit 1
fi
echo ''
echo ''
echo 'prerequisites complete:'
echo '[x] jq'
echo '[x] /Applications/MacUpdater.app/Contents/Resources/macupdater_client'
echo ''
echo 'now running macupdater_client to update all outdated apps that can be updated...'
outdated=$(/Applications/MacUpdater.app/Contents/Resources/macupdater_client list --hide-uptodate-apps --hide-mas-apps --hide-unsupported-apps --quiet --json | jq -r '.apps[] .installed_path')
if [ -z "$outdated" ]; then
echo 'no apps to update...'
echo 'done!'
else
echo "found apps to update..."
echo ''
while IFS= read -r app; do
echo "> updating $app"
echo " /Applications/MacUpdater.app/Contents/Resources/macupdater_client update --quiet $app"
/Applications/MacUpdater.app/Contents/Resources/macupdater_client update --quiet "$app"
done <<<"$outdated"
echo ''
echo 'done!'
fi
@solrevdev
Copy link
Author

solrevdev commented Jan 14, 2022

Response back from Vitor from macupdater that does not need jq to be installed.

#!/bin/bash

# Get outdated paths as array
IFS=$'\n' read -d '' -ra outdated_apps < <(/usr/bin/osascript -l JavaScript -e 'function run(argv) { return JSON.parse(argv[0])["apps"].map(a => a["installed_path"]).join("\n") }' "$(/Applications/MacUpdater.app/Contents/Resources/macupdater_client list --hide-uptodate-apps --json)")

# Update apps
for app_path in "${outdated_apps[@]}"; do
 /Applications/MacUpdater.app/Contents/Resources/macupdater_client update --quiet "${app_path}"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment