Skip to content

Instantly share code, notes, and snippets.

@JohnSundell
Created June 17, 2017 13:29
Show Gist options
  • Save JohnSundell/620c3d12aca69fbe259f69391cc532f8 to your computer and use it in GitHub Desktop.
Save JohnSundell/620c3d12aca69fbe259f69391cc532f8 to your computer and use it in GitHub Desktop.
A script that switches between the App Store & beta versions of Xcode
#!/usr/bin/env bash
# This script switches between the App Store version of Xcode and the beta
# Install it by copying it to /usr/local/bin/xcode-switch and running 'chmod +x' on it (to make it executable)
# Then run it using 'sudo xcode-switch'
if [ "$EUID" -ne 0 ]; then
echo "xcode-select requires you to run this script as root; 'sudo xcode-switch'"
exit
fi
currentPath=$(xcode-select -p)
if [ "$currentPath" == "/Applications/Xcode.app/Contents/Developer" ]; then
xcode-select -s "/Applications/Xcode-beta.app/Contents/Developer"
else
xcode-select -s "/Applications/Xcode.app/Contents/Developer"
fi
newPath=$(xcode-select -p)
echo "Xcode path is now $newPath"
@AliSoftware
Copy link

Alternative idea (not tested), to avoid requiring sudo and instead switch the Xcode version on a per-invocation basis:

$ cat x8
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer" $@

$ cat x9
#!/usr/bin/env bash
DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer" $@

# Usage
$ x9 xcodebuild -workspace …

@LH17
Copy link

LH17 commented Jun 22, 2017

Good one @JohnSundell 👍

@sxcore
Copy link

sxcore commented Jul 3, 2017

Is it working with Oh-My-ZSH?

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