Skip to content

Instantly share code, notes, and snippets.

@timsutton
Created September 24, 2021 17:42
Show Gist options
  • Save timsutton/26fecc3922daaf123988036ffaaf2a8c to your computer and use it in GitHub Desktop.
Save timsutton/26fecc3922daaf123988036ffaaf2a8c to your computer and use it in GitHub Desktop.
import Foundation
print(LSCopyApplicationURLsForBundleIdentifier("com.apple.dt.Xcode" as CFString, nil))
@timsutton
Copy link
Author

timsutton commented Sep 24, 2021

Returns on b7 - system has Xcode 12.5.1 and 13.0 installed:

ProductName:	macOS
ProductVersion:	12.0
BuildVersion:	21A5522h

$ ./UrlsForBundleIdentifier 
Optional(Swift.Unmanaged<__C.CFArrayRef>(_value: <__NSSingleObjectArrayI 0x60000382c030>(
file:///Applications/Xcode/13.0/Xcode.app/
)
))

On b6 - system has Xcode 12.1 and 12.5.1 installed::

$ sw_vers
ProductName:	macOS
ProductVersion:	12.0
BuildVersion:	21A5506j

$ /tmp/UrlsForBundleIdentifier 
Optional(Swift.Unmanaged<__C.CFArrayRef>(_value: <__NSArrayI 0x600000aae620>(
file:///Applications/Xcode/12.5.1/Xcode.app/,
file:///Applications/Xcode/12.1.0/Xcode.app/
)
))

@timsutton
Copy link
Author

Can also get output of Bazel's xcode_locator via:

$ bazel run tools/osx:xcode-locator

INFO: Analyzed target //tools/osx:xcode-locator (5 packages loaded, 16 targets configured).
INFO: Found 1 target...
Target //tools/osx:xcode-locator up-to-date:
  bazel-bin/tools/osx/xcode-locator
INFO: Elapsed time: 16.136s, Critical Path: 13.89s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed successfully, 2 total actions
INFO: Build completed successfully, 2 total actions
2021-09-24 11:30:00.738 xcode-locator[30134:168019] Found bundle com.apple.dt.Xcode in file:///Applications/Xcode/13.0/Xcode.app/; contents on disk: (
    "file:///Applications/Xcode/13.0/Xcode.app/Contents/"
)
2021-09-24 11:30:00.743 xcode-locator[30134:168019] Version strings for file:///Applications/Xcode/13.0/Xcode.app/: short=13.0, expanded=13.0.0
{
	"13.0": "/Applications/Xcode/13.0/Xcode.app/Contents/Developer",
	"13": "/Applications/Xcode/13.0/Xcode.app/Contents/Developer",
	"13A233": "/Applications/Xcode/13.0/Xcode.app/Contents/Developer",
	"13.0.0": "/Applications/Xcode/13.0/Xcode.app/Contents/Developer",
	"13.0.0.13A233": "/Applications/Xcode/13.0/Xcode.app/Contents/Developer"
}

@timsutton
Copy link
Author

Output of lsregister -dump for Xcode 12.5.1, showing for example computed bundle flags, is below.

lsregister outputs some values colored in red, which doesn't show below, but in bundle flags we see version-too-low and unsupported-format, which don't show for Xcode 13.0.

$ /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -dump

<snip>


--------------------------------------------------------------------------------
bundle id:                  Xcode (0x55c)
class:                      kLSBundleClassApplication (0x2)
container:                  / (0x4)
mount state:                mounted
Mach-O UUIDs:               C33152EB-ED95-3847-A633-36174AB4AC81, A5E72020-95EB-367B-B953-F696FAC98C5A
sequenceNum:                1372
path:                       /Applications/Xcode/12.5.1/Xcode.app (0xe88)
directory:                  /Applications
name:                       Xcode
displayName:                Xcode
localizedNames:             "en" = ?, "English" = ?, "LSDefaultLocalizedValue" = "Xcode"
localizedShortNames:        "en" = ?, "English" = ?, "LSDefaultLocalizedValue" = "Xcode"
teamID:                     59GAB85EFG
category:                   public.app-category.developer-tools (0x4898)
identifier:                 com.apple.dt.Xcode
canonical id:               com.apple.dt.xcode
version:                    18212.0 ({length = 32, bytes = 0x24470000 00000000 00000000 00000000 ... 00000000 00000000 })
versionString:              18212
displayVersion:             12.5.1
mod date:                   2021-06-08 17:41 (POSIX 1623199288, 𝛥 3mths 2wks 3days 19hr 2min 48sec)
reg date:                   2021-09-24 11:18 (POSIX 1632507506, 𝛥 25min 50sec)
rec mod date:               2021-09-24 11:18 (POSIX 1632507506, 𝛥 25min 50sec)
type code:                  'APPL' (4150504c)
creator code:               '????' (3f3f3f3f)
bundle flags:               has-display-name  version-too-low  wildcard  dev-tool (0040000010004002)
plist flags:                has-environment  has-custom-bindings (0000000000010001)
icon flags:                 relative-icon-path  supports-asset-catalog (0000000000000005)
slices:                     x86_64  arm64 (0000000000000088)
item flags:                 package  application  container  native-app  scriptable  extension-hidden  services  unsupported-format (000000000070088e)
base flags:                 apple-internal
App Nap:                    capable (0000000000000001)
eGPU:                       capable  can-change (0000000000000005)
platform:                   native
iconName:                   Xcode
iconDict:                   1 values (18448 (0x4810))
                            {
                                CFBundlePrimaryIcon =     {
                                    CFBundleIconFile = Xcode;
                                    CFBundleIconName = Xcode;
                                };
                            }
icons:                      Contents/Resources/Xcode.icns
executable:                 Contents/MacOS/Xcode
inode:                      2518235
exec inode:                 2537745
min version:                11.0 ({length = 32, bytes = 0x0b000000 00000000 00000000 00000000 ... 00000000 00000000 })
min version platform:       native
execSDK ver:                11.3 ({length = 32, bytes = 0x0b000000 00000000 03000000 00000000 ... 00000000 00000000 })
mach min ver:               10.15 ({length = 32, bytes = 0x0a000000 00000000 0f000000 00000000 ... 00000000 00000000 })
infoDictionary:             25 values (18452 (0x4814))
                            {
                                CFBundleDevelopmentRegion = English;
                                CFBundleDisplayName = Xcode;
                                CFBundleExecutable = Xcode;
                                CFBundleHelpBookFolder = "Xcode.help";
                                CFBundleHelpBookName = "com.apple.dt.Xcode.help";
                                CFBundleIconFile = Xcode;
                                CFBundleIconName = Xcode;
                                CFBundleIdentifier = "com.apple.dt.Xcode";
                                CFBundleInfoDictionaryVersion = "6.0";
                                CFBundleName = Xcode;
                                CFBundlePackageType = APPL;
                                CFBundleShortVersionString = "12.5.1";
                                CFBundleSignature = "????";
                                CFBundleSupportedPlatforms =     (
                                    MacOSX
                                );
                                CFBundleVersion = 18212;
                                LSEnvironment =     {
                                    MallocNanoZone = 0;
                                };
                                NSAppleScriptEnabled = 1;
                                NSContactsUsageDescription = "Xcode can pair your contacts with Source Control users for enhanced collaboration.";
                                NSExtensionSDK =     {
                                    "com.apple.dt.Xcode.extension.source-control-host" =         {
                                        CFBundlePackageType = "XPC!";
                                        NSExtension =             {
                                            NSExtensionAttributes =                 {
                                                NSExtensionPointName = "com.apple.dt.Xcode.extension.source-control-host";
                                                NSExtensionVersion = "1.0";
                                            };
                                            NSExtensionContextClass = XCExtensionServiceContext;
                                            NSExtensionContextHostClass = XCExtensionHostContext;
                                            NSExtensionPrincipalClass = XCExtensionPrincipalClass;
                                            NSExtensionProtocol = NSObject;
                                            PrincipalClass = NSObject;
                                            Subsystems =                 (
                                                XCExtensionSubsystem
                                            );
                                        };
                                        NSExtensionPointIdentifier = "com.apple.dt.Xcode.extension.source-control-host";
                                        XPCService =             {
                                            JoinExistingSession = 1;
                                            RunLoopType = NSRunLoop;
                                            ServiceType = Application;
                                            "_AdditionalSubServices" =                 {
                                                "apple-extension-service" = 1;
                                            };
                                            "_LaunchWatchdogTimeOut" = 180;
                                        };
                                    };
                                    "com.apple.dt.Xcode.extension.source-editor" =         {
                                        CFBundlePackageType = "XPC!";
                                        NSExtension =             {
                                            NSExtensionAttributes =                 {
                                                NSExtensionPointName = "com.apple.dt.Xcode.extension.source-editor";
                                                NSExtensionVersion = "1.0";
                                            };
                                            NSExtensionContextClass = XCExtensionServiceContext;
                                            NSExtensionContextHostClass = XCExtensionHostContext;
                                            NSExtensionPrincipalClass = XCExtensionPrincipalClass;
                                            NSExtensionProtocol = NSObject;
                                            PrincipalClass = NSObject;
                                            Subsystems =                 (
                                                XCExtensionSubsystem
                                            );
                                        };
                                        NSExtensionPointIdentifier = "com.apple.dt.Xcode.extension.source-editor";
                                        XPCService =             {
                                            JoinExistingSession = 1;
                                            RunLoopType = NSRunLoop;
                                            ServiceType = Application;
                                            "_AdditionalSubServices" =                 {
                                                "apple-extension-service" = 1;
                                            };
                                            "_LaunchWatchdogTimeOut" = 180;
                                        };
                                    };
                                };
                                NSHumanReadableCopyright = "Copyright \U00a9 1999\U20132021 Apple Inc. All rights reserved.";
                                NSMainNibFile = MainMenu;
                                NSPrincipalClass = IDEApplication;
                                NSSupportsAutomaticGraphicsSwitching = 1;
                                NSSupportsAutomaticTermination = 1;
                                NSSupportsSuddenTermination = 1;
                            }
library:                    Contents/Library/
library items:              Spotlight/uuid.mdimporter/, QuickLook/DVTProvisioningProfileQuicklookGenerator.qlgenerator/
activityTypes:              NOTIFICATION#59GAB85EFG:com.apple.dt.Xcode, pv-c2055812f84bc3
claimed UTIs:               com.apple.xcode.strings-text, public.swift-source, public.tcsh-script, com.apple.text-based-dylib, public.c-plus-plus-header, public.objective-c-plus-plus-source, com.apple.dt.document.geojson, com.apple.xcode.apinotes, com.apple.xcode.plugindata.compiled, org.khronos.glsl.geometry-shader, com.apple.xml-property-list, com.apple.scenekit.scene, com.apple.xcode.model.data-version, public.php-script, com.apple.coreml.mlmodelkey, public.nasm-assembly-source, com.apple.dt.xctestplancontenttype, com.apple.dt.playground, com.apple.crashreport, com.apple.coreml.mlarchive, com.apple.dt.document.workspace, com.apple.xcode.model.data, com.apple.rez-source, com.apple.iphone.ipsw, com.apple.dt.ide.debughierarchycontenttype, com.apple.interfacebuilder.document.cocoa, com.apple.symbol-export, public.shell-script, com.apple.xcode.project, public.precompiled-c-plus-plus-header, com.apple.dt.document.script-terminology-property-list, com.apple.xcode.strings-dictionary, public.assembly-source, com.apple.dt.document.xccrashpoint, public.objective-c-source, com.apple.dt.document.xcprocessorusagepoint, public.mig-source, com.apple.xcode.model.data-mapping, com.apple.dt.ide.memorygraphdebuggercontenttype, com.apple.xcode.projectdata, org.khronos.glsl-source, public.rtf, com.apple.coreml.mlmodelc, org.khronos.glsl.tess-evaluation-shader, public.perl-script, com.apple.dt.document.apns, public.script, org.khronos.glsl.tess-control-shader, com.apple.dt.document.xcdiskwritepoint, com.apple.scenekit.scene.zip, com.apple.dt.interfacebuilder.document.storyboard, public.text, public.yaml, public.c-header, com.apple.xcode.appdata, com.apple.coreml.model, com.apple.xcode.archive, com.apple.xcode.resultbundle, public.make-source, org.khronos.glsl.fragment-shader, com.apple.dt.document.xcprocessorusagelog, public.python-script, com.apple.metal, com.apple.scripting-definition, com.apple.interfacebuilder.document, com.apple.scenekit.particlesystem, com.apple.sirikit.intentdefinition, com.pixar.universal-scene-description, com.apple.lsr-image, com.apple.dt.document.xcdiskwritelog, com.apple.xcode.plugindata, com.pixar.usd.crate, com.apple.iig-source, com.apple.clips-source, public.data, public.csh-script, public.xml, com.apple.dt.document.xcmetricsdata, net.daringfireball.markdown, public.bash-script, com.apple.xcode.entitlements-property-list, com.apple.xcode.xcfilelist, com.apple.instruments.package-definition, com.apple.applescript.text, com.apple.dt.xcodeserver-integration, com.pixar.universal-scene-description-mobile, com.apple.spritekit.serialized, com.apple.dt.document.ascii-property-list, org.khronos.glsl.vertex-shader, org.oasis-open.xliff, public.geometry-definition-format, com.apple.provisionprofile, com.apple.xcode.buildmetrics, com.apple.dt.document.gpx, public.ruby-script, public.json, com.apple.iphone.mobileprovision, com.apple.xcode.usersettings, com.apple.iphone.developerprofile, public.source-code, com.pixar.usd.ascii, com.apple.dt.xctestruncontenttype, com.apple.rtfd, public.c-plus-plus-source, com.apple.gputools.gputrace, com.apple.xcode.configsettings, public.ksh-script, com.apple.dt.playgroundpage, com.apple.dt.document.script-suite-property-list, public.precompiled-c-header, com.apple.mobileprovision, public.standard-tesselated-geometry-format, public.polygon-file-format, com.apple.dt.storekit, public.opencl-source, com.apple.dt.interfacebuilder.document.storyboard.package, public.zsh-script, public.c-source, public.module-map, com.apple.binary-property-list, com.apple.property-list, com.apple.arobject
claimed schemes:            apple-reference-documentation:, doc:, interface-builder:, x-xcode-documentation:, xcbot:, xcdevice:, xcdoc:, xcode:, xcpref:
entitlements:               20 values (18456 (0x4818))
                            {
                                "com.apple.PairingManager.Read" = 1;
                                "com.apple.PairingManager.RemovePeer" = 1;
                                "com.apple.PairingManager.Write" = 1;
                                "com.apple.application-identifier" = "59GAB85EFG.com.apple.dt.Xcode";
                                "com.apple.authkit.client.private" = 1;
                                "com.apple.corespotlight.privateindex.unsandboxed" = 1;
                                "com.apple.developer.aps-environment" = production;
                                "com.apple.developer.maps" = 1;
                                "com.apple.dt.simulator.client" = 1;
                                "com.apple.private.AuthorizationServices" =     (
                                    "com.apple.trust-settings.admin"
                                );
                                "com.apple.private.MobileContainerManager.lookup" =     {
                                    appData = 1;
                                    pluginData = 1;
                                };
                                "com.apple.private.OAHSoftwareUpdate" = 1;
                                "com.apple.private.coreservices.definesExtensionPoint" = 1;
                                "com.apple.private.dt.xcode.set-responsible-process-for-ui-testing" = 1;
                                "com.apple.private.syspolicy.execution-policy-bypass" = 1;
                                "com.apple.private.tcc.allow" =     (
                                    kTCCServiceAppleEvents,
                                    kTCCServicePhotos,
                                    kTCCServiceDeveloperTool
                                );
                                "com.apple.private.tcc.allow-prompting" =     (
                                    kTCCServiceAll
                                );
                                "com.apple.runningboard.assertions.chronod" = 1;
                                "com.apple.springboard.debugapplications" = 1;
                                "com.apple.sysmond.client" = 1;
                            }
--------------------------------------------------------------------------------

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