public
Last active

Helps for developing scripts that need to know the actual SDK path.

  • Download Gist
ios_sdk
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#!/usr/bin/python
 
import plistlib
import os
import commands
import argparse
 
DEVELOPER_DIR = commands.getoutput('/usr/bin/xcode-select -print-path')
PLATFORMS_DIRECTORY = os.path.join(DEVELOPER_DIR, "Platforms")
IPHONE_PLATFORM = "iPhoneOS.platform"
SIMULATOR_PLATFORM = "iPhoneSimulator.platform"
PLIST_FILE = "Info.plist"
 
def find_version(platform):
path = None
if (platform == 'iphoneos'):
path = os.path.join(PLATFORMS_DIRECTORY, IPHONE_PLATFORM, PLIST_FILE)
elif (platform == 'iphonesimulator'):
path = os.path.join(PLATFORMS_DIRECTORY, SIMULATOR_PLATFORM, PLIST_FILE)
else:
return None
version = plistlib.readPlist(path).CFBundleShortVersionString
return version
 
def get_sdk_path(platform, version):
path = None
if (platform == 'iphoneos'):
path = os.path.join(PLATFORMS_DIRECTORY, IPHONE_PLATFORM, "Developer", "SDKs", "iPhoneOS{0}.sdk".format(version))
elif (platform == 'iphonesimulator'):
path = os.path.join(PLATFORMS_DIRECTORY, SIMULATOR_PLATFORM, "Developer", "SDKs", "iPhoneSimulator{0}.sdk".format(version))
else:
return None
return path
 
 
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Returns the version of the currently installed platform sdk.')
parser.add_argument('-iphoneos', action='store_const', dest='platform', const='iphoneos')
parser.add_argument('-iphonesimulator', action='store_const', dest='platform', const='iphonesimulator')
parser.add_argument('-path', action='store_true', dest='showPath', default=False)
args = parser.parse_args()
 
if args.platform is None:
parser.print_help()
exit(0)
version = find_version(args.platform)
 
if (args.showPath):
print get_sdk_path(args.platform, version)
else:
print version

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.