-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremy Knope
committed
Mar 13, 2015
1 parent
4f11496
commit 11cd407
Showing
4 changed files
with
285 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/python | ||
|
||
import os.path | ||
import sys | ||
from subprocess import check_output, call | ||
import re | ||
|
||
device_id = sys.argv[1] | ||
|
||
device_name = "Unknown" | ||
|
||
def is_device_running(device_id): | ||
result = check_output(['xcrun', 'simctl', 'list']) | ||
name = None | ||
for line in result.split('\n'): | ||
m = re.search("(\s+)(.*)\s\(([\d\w]{8}-[\w\d]{4}-[\w\d]{4}-[\w\d]{4}-[\w\d]{12})\)\s+\((\w+)\)(\s+\((unavailable).*)?", line) | ||
if m: | ||
device_id_check = m.group(3) | ||
if device_id == device_id_check: | ||
name = m.group(2) | ||
device_id_check = m.group(3) | ||
device_status = m.group(4) | ||
if "Booted" == device_status: | ||
return True, name | ||
return False, name | ||
|
||
isRunning, device_name = is_device_running(device_id) | ||
|
||
# uninstall app | ||
if not isRunning: | ||
result = call(['xcrun', 'simctl', 'erase', device_id]) | ||
if result != 0: | ||
print "Failed to erase device: %s" % (device_name) | ||
else: | ||
print 'Erased %s' % (device_name) | ||
else: | ||
print "Can't erase %s, already booted" % (device_name) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/python | ||
# encoding: utf-8 | ||
|
||
import sys | ||
import argparse | ||
import simctl | ||
from workflow import (Workflow, ICON_WEB, ICON_INFO, ICON_WARNING, | ||
PasswordNotFound) | ||
from workflow.background import run_in_background, is_running | ||
|
||
|
||
def search_key_for_device(device): | ||
"""Generate a string search key for a device""" | ||
elements = [] | ||
elements.append(device['name']) | ||
elements.append(device['id']) | ||
return u' '.join(elements) | ||
|
||
|
||
def main(wf): | ||
|
||
# build argument parser to parse script args and collect their | ||
# values | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('query', nargs='?', default=None) | ||
# parse the script's arguments | ||
args = parser.parse_args(wf.args) | ||
|
||
#################################################################### | ||
# View/filter Simulator apps | ||
#################################################################### | ||
|
||
query = args.query | ||
siminfo = simctl.SimControl() | ||
devices = siminfo.activeDevices() | ||
|
||
|
||
# If script was passed a query, use it to filter posts if we have some | ||
if query and devices: | ||
devices = wf.filter(query, devices, key=search_key_for_device, min_score=20) | ||
|
||
if not devices: # we have no data to show, so show a warning and stop | ||
wf.add_item('No devices found', icon=ICON_WARNING) | ||
wf.send_feedback() | ||
return 0 | ||
|
||
# Loop through the returned posts and add a item for each to | ||
# the list of results for Alfred | ||
for device in devices: | ||
deviceName = '%s (%s)' % (device['name'], device['version']) | ||
|
||
wf.add_item(title=deviceName, | ||
subtitle=', '.join(device['xcodes']), | ||
arg=device['id'], | ||
valid=True, | ||
uid=device['id']) | ||
|
||
# Send the results to Alfred as XML | ||
wf.send_feedback() | ||
return 0 | ||
|
||
|
||
if __name__ == u"__main__": | ||
wf = Workflow() | ||
sys.exit(wf.run(main)) |
Oops, something went wrong.