Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@AliSoftware AliSoftware commented Jun 17, 2017

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

This comment has been minimized.

Copy link

@LH17 LH17 commented Jun 22, 2017

Good one @JohnSundell 👍

@Drwalcore

This comment has been minimized.

Copy link

@Drwalcore Drwalcore 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