Skip to content

Instantly share code, notes, and snippets.

@ziggear
Created October 28, 2014 07:09
Show Gist options
  • Save ziggear/d1dd5470185427c9c7ec to your computer and use it in GitHub Desktop.
Save ziggear/d1dd5470185427c9c7ec to your computer and use it in GitHub Desktop.
Find all Xcode6 Simulators
import os, re, commands
temp_file_name = "temp.txt"
command = "xcrun simctl list > %s" % temp_file_name
os.popen(command)
ios_list = {}
cur_ios = None
regex_block = re.compile(r"-- (iOS [5-8].[0-9]) --")
regex_inner = re.compile(r"(.*?)([0-9A-Za-z]*)\((.*?)\) \((.*?)\)")
temp_file = open(temp_file_name)
user_root = commands.getoutput("echo ~")
simulator_root = "%s/iPhone Simulators" % (user_root)
cmd = "mkdir \"%s\"" % (simulator_root)
os.popen(cmd)
if temp_file :
while 1:
line = temp_file.readline()
if not line:
break
res = regex_block.findall(line)
if (len(res)) :
cur_ios = res[0]
if ios_list.get(cur_ios) == None :
ios_list[cur_ios] = []
cmd = "mkdir '%s/%s'" % (simulator_root, cur_ios)
os.popen(cmd)
else :
res = regex_inner.findall(line)
if (len(res)) and cur_ios != None :
device_name = res[0][0].strip()
device_id = res[0][2]
device_path = "%s/Library/Developer/CoreSimulator/Devices/%s/" % (user_root, device_id)
cmd = "ln -s \"%s\" \"%s/%s/%s\" " % (device_path, simulator_root, cur_ios, device_name)
os.popen(cmd)
temp_file.close()
os.popen("rm temp.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment