Skip to content

Instantly share code, notes, and snippets.

@mseijas
Created June 15, 2021 17:29
Show Gist options
  • Save mseijas/f0ebc94224cfa6ba73415d98e7cb6881 to your computer and use it in GitHub Desktop.
Save mseijas/f0ebc94224cfa6ba73415d98e7cb6881 to your computer and use it in GitHub Desktop.
Open active Xcode version
function openxcode() {
if pgrep -x "Xcode" > /dev/null; then
read -k 1 "USER_INPUT?Xcode is already running. Close running version first? (y/N) "
if [[ "$USER_INPUT" =~ ^[Yy]$ ]]; then
killall Xcode
fi
fi
ACTIVE_XCODE_DIRECTORY=$(xcode-select -p)
SUFFIX_LENGTH=19 # "/Contents/Developer"
ACTIVE_XCODE_PATH=$(sed "s/.\{$SUFFIX_LENGTH\}$//" <<<"$ACTIVE_XCODE_DIRECTORY")
SYMLINK_PATH="/Applications/Xcode.app"
rm -f $SYMLINK_PATH
ln -sf $ACTIVE_XCODE_PATH $SYMLINK_PATH
open -a "$SYMLINK_PATH" "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment