Skip to content

Instantly share code, notes, and snippets.

@steeve
Created November 15, 2021 21:03
Show Gist options
  • Save steeve/4e5d37ca9a07d4a796b909a6c9ae6156 to your computer and use it in GitHub Desktop.
Save steeve/4e5d37ca9a07d4a796b909a6c9ae6156 to your computer and use it in GitHub Desktop.
Xcode 12.5 + Monterey
#!/bin/bash
set -eux
readonly xcode12="/Applications/Xcode-12.5.0.app"
readonly xcode13="/Applications/Xcode-13.1.0.app"
# Backup Xcode 12 Info.plist
cp "${xcode12}/Contents/Info.plist" "${xcode12}/Contents/Info.plist.bak"
# Extract Xcode 13's CFBundleVersion
readonly xcode13_version=$(/usr/bin/plutil -extract "CFBundleVersion" raw "${xcode13}/Contents/Info.plist")
# Put Xcode 13's CFBundleVersion inside Xcode 12's Info.plist
/usr/bin/plutil -replace "CFBundleVersion" -string "${xcode13_version}" "${xcode12}/Contents/Info.plist"
# Open Xcode 12 so that the bundle is registered
open "${xcode12}"
# Sleep 5 seconds to let it start, kill it, and restore the original Info.plist
sleep 5
pkill -f Xcode
mv "${xcode12}/Contents/Info.plist.bak" "${xcode12}/Contents/Info.plist"
# Reopen it in case lsd needs to refresh the CFBundleVersion
open "${xcode12}"
@timsutton
Copy link

Another option for forcing registrations / LSD updates, you can also explicitly ask LS to register it instead of calling open on the bundle. So I think you should be able to replace open "${xcode12}" with:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
  -f -v "${xcode12}"

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