Skip to content

Instantly share code, notes, and snippets.

@cmer
Created June 16, 2020 19:05
Show Gist options
  • Save cmer/4c26d3b9d2f7deaea4ba8f0772dc089a to your computer and use it in GitHub Desktop.
Save cmer/4c26d3b9d2f7deaea4ba8f0772dc089a to your computer and use it in GitHub Desktop.
Install last downloaded file on macOS
#/bin/bash
# Install the last downloaded file on macOS
dl_path=~/Downloads
last_dl=`ls -tl -A1 $dl_path/*.{dmg,pkg} | head -n1`
if [[ $last_dl == *.dmg ]]; then
echo "Installing DMG: $last_dl..."
VOLUME=$(hdiutil attach -nobrowse "$last_dl" | cut -f3 | tail -n1 ; exit ${PIPESTATUS[0]}) && (rsync -a "$VOLUME"/*.app /Applications/; SYNCED=$?
hdiutil detach -quiet "$VOLUME"; exit $? || exit "$SYNCED")
fi
if [[ $last_dl == *.pkg ]]; then
echo "Opening PKG: $last_dl..."
open "$last_dl"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment