Skip to content

Instantly share code, notes, and snippets.

@demonnic
Last active April 19, 2023 19:36
Show Gist options
  • Save demonnic/2ea29a12da9b10beae71f83e196e9d5a to your computer and use it in GitHub Desktop.
Save demonnic/2ea29a12da9b10beae71f83e196e9d5a to your computer and use it in GitHub Desktop.
Script to install or update XCode Command Line Tools. Tested working on MacOS 13.3.1 on 2023-04-19
#!/usr/bin/env bash
cliLocation="/Library/Developer/CommandLineTools"
tmpFile="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
if [[ ! -d "$cliLocation" ]]
then
touch $tmpFile
fi
PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | sed 's/^[^C]* //')
if [[ ! -z $PROD ]]
then
softwareupdate -i "$PROD" --verbose
if [[ -f "$tmpFile" ]]
then
rm $tmpFile
fi
else
echo "Command Line Tools are up to date"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment