Created
June 16, 2020 19:05
-
-
Save cmer/4c26d3b9d2f7deaea4ba8f0772dc089a to your computer and use it in GitHub Desktop.
Install last downloaded file on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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