Last active
April 8, 2018 00:09
-
-
Save pudquick/778b7c5667aae52706e78a4f6489505a to your computer and use it in GitHub Desktop.
Programmatically load detailed version information about Xcode version via pyobjc on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Warning - because of how this works, it loads classes into memory namespace. | |
# Attempting to load a second Xcode to inspect within the same python run will result in errors | |
# If you need to inspect multiple, for now, just spin the inspection up under a second process | |
from Foundation import NSBundle | |
def xcode_info(app_path): | |
# app_path = '/Applications/Xcode.app' | |
DVTFoundation = NSBundle.bundleWithPath_('%s/Contents/SharedFrameworks/DVTFoundation.framework' % app_path) | |
IDEKit = NSBundle.bundleWithPath_('%s/Contents/Frameworks/IDEKit.framework' % app_path) | |
DVTToolsInfo = DVTFoundation.classNamed_('DVTToolsInfo') | |
x_info = DVTToolsInfo.toolsInfo() | |
x_v = x_info.toolsVersion() | |
x_b = x_info.toolsBuildVersion() | |
d = dict() | |
d['name'] = x_v.name() | |
d['major'] = x_v.versionMajorComponent() | |
d['minor'] = x_v.versionMinorComponent() | |
d['update'] = x_v.versionUpdateComponent() | |
d['build'] = x_b.name() | |
d['is_beta'] = x_info.isBeta() | |
d['beta_version'] = 0 | |
if d['is_beta']: | |
d['beta_version'] = x_info.toolsBetaVersion() | |
beta_str = '' | |
if d['is_beta']: | |
beta_str = 'beta ' | |
if d['beta_version'] >= 2: | |
beta_str = 'beta %s ' % (d['beta_version']) | |
d['display'] = '%s %s(%s)' % (d['name'], beta_str, d['build']) | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment