Skip to content

Commit

Permalink
Fix utf8 errors & add 'sima' for locating actual sim apps
Browse files Browse the repository at this point in the history
  • Loading branch information
jfro committed Apr 8, 2015
1 parent 8d41d71 commit 153e245
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 76 deletions.
11 changes: 9 additions & 2 deletions find_sim_apps.py
Expand Up @@ -7,6 +7,7 @@
from workflow import (Workflow, ICON_WEB, ICON_INFO, ICON_WARNING,
PasswordNotFound)
from workflow.background import run_in_background, is_running
from os.path import dirname


def search_key_for_app(app):
Expand All @@ -25,6 +26,9 @@ def main(wf):
parser = argparse.ArgumentParser()

parser.add_argument('query', nargs='?', default=None)
parser.add_argument('--apps', dest='appPaths',
const=True, default=False, action='store_const',
help='Produces path to apps instead')
# parse the script's arguments
args = parser.parse_args(wf.args)

Expand All @@ -33,6 +37,7 @@ def main(wf):
####################################################################

query = args.query
appPaths = args.appPaths

apps = siminfo.getSimAppResults(wf.cachedir)

Expand All @@ -50,10 +55,12 @@ def main(wf):
# the list of results for Alfred
for app in apps:
appName = '%s (%s - %s)' % (app['name'], app['device']['name'], app['device']['runtime'])

path = app['data_path']
if appPaths:
path = dirname(app['path'])
wf.add_item(title=appName,
subtitle=app['short_path'] + ' - ' + app['id'],
arg=app['data_path'],
arg=path,
valid=True,
icon=app['icon'],
uid=app['data_path'])
Expand Down
199 changes: 126 additions & 73 deletions info.plist
Expand Up @@ -85,6 +85,17 @@
<string></string>
</dict>
</array>
<key>FAB50204-41C8-459B-A7C4-55C2452D7033</key>
<array>
<dict>
<key>destinationuid</key>
<string>4EB61527-10BC-40EE-9185-E988A89344D7</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Jeremy Knope</string>
Expand All @@ -93,9 +104,19 @@
<key>disabled</key>
<false/>
<key>name</key>
<string>iOS Simulator v1.2</string>
<string>iOS Simulator v1.3</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict/>
<key>type</key>
<string>alfred.workflow.action.openfile</string>
<key>uid</key>
<string>4EB61527-10BC-40EE-9185-E988A89344D7</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -135,13 +156,65 @@
</dict>
<dict>
<key>config</key>
<dict/>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<key>output</key>
<integer>0</integer>
<key>removeextension</key>
<false/>
<key>sticky</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Uninstall Simulator App</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.openfile</string>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>4EB61527-10BC-40EE-9185-E988A89344D7</string>
<string>04421F78-4E29-45C8-95EC-987A6F26F016</string>
<key>version</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>127</integer>
<key>keyword</key>
<string>sima</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Searching for apps matching {query}</string>
<key>script</key>
<string>python ./find_sim_apps.py --apps "{query}"</string>
<key>subtext</key>
<string>Open location of an iOS Simulator app</string>
<key>title</key>
<string>Simulator apps</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>FAB50204-41C8-459B-A7C4-55C2452D7033</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -163,25 +236,17 @@
<dict>
<key>config</key>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<key>output</key>
<key>escaping</key>
<integer>127</integer>
<key>script</key>
<string>ruby ./reset-all.rb</string>
<key>type</key>
<integer>0</integer>
<key>removeextension</key>
<false/>
<key>sticky</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Uninstall Simulator App</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>04421F78-4E29-45C8-95EC-987A6F26F016</string>
<string>0F91FB1D-068E-48DE-AF19-A5DFA2A1A2F3</string>
<key>version</key>
<integer>0</integer>
</dict>
Expand Down Expand Up @@ -225,21 +290,25 @@
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>2</integer>
<key>keyword</key>
<string>simreset</string>
<key>subtext</key>
<string>Resets all iOS simulators in all found Xcodes</string>
<key>text</key>
<string>Reset iOS Simulators</string>
<key>withspace</key>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<key>output</key>
<integer>0</integer>
<key>removeextension</key>
<false/>
<key>sticky</key>
<false/>
<key>text</key>
<string>All iOS Simulators have been Reset if possible</string>
<key>title</key>
<string>Simulators Reset</string>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>15E7ABF3-218E-47E5-B120-83DEBC938433</string>
<string>7A9B4E1F-0B3A-40F9-A85A-201C599CDD90</string>
<key>version</key>
<integer>0</integer>
</dict>
Expand All @@ -249,14 +318,14 @@
<key>escaping</key>
<integer>127</integer>
<key>script</key>
<string>ruby ./reset-all.rb</string>
<string>python ./erase_device.py "{query}"</string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>0F91FB1D-068E-48DE-AF19-A5DFA2A1A2F3</string>
<string>C7DBD597-2AC9-4177-BC16-176EBB6A2D86</string>
<key>version</key>
<integer>0</integer>
</dict>
Expand All @@ -274,31 +343,35 @@
<key>sticky</key>
<false/>
<key>text</key>
<string>All iOS Simulators have been Reset if possible</string>
<string>{query}</string>
<key>title</key>
<string>Simulators Reset</string>
<string>Simulator Erased</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>7A9B4E1F-0B3A-40F9-A85A-201C599CDD90</string>
<string>C11961A2-A67A-4D48-8792-90AA10AD8E4C</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>escaping</key>
<integer>127</integer>
<key>script</key>
<string>python ./erase_device.py "{query}"</string>
<key>type</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>2</integer>
<key>keyword</key>
<string>simreset</string>
<key>subtext</key>
<string>Resets all iOS simulators in all found Xcodes</string>
<key>text</key>
<string>Reset iOS Simulators</string>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>C7DBD597-2AC9-4177-BC16-176EBB6A2D86</string>
<string>15E7ABF3-218E-47E5-B120-83DEBC938433</string>
<key>version</key>
<integer>0</integer>
</dict>
Expand Down Expand Up @@ -339,31 +412,6 @@
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<key>output</key>
<integer>0</integer>
<key>removeextension</key>
<false/>
<key>sticky</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Simulator Erased</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>C11961A2-A67A-4D48-8792-90AA10AD8E4C</string>
<key>version</key>
<integer>0</integer>
</dict>
</array>
<key>readme</key>
<string></string>
Expand All @@ -382,7 +430,7 @@
<key>15E7ABF3-218E-47E5-B120-83DEBC938433</key>
<dict>
<key>ypos</key>
<real>240</real>
<real>340</real>
</dict>
<key>38DFD2DA-6DD1-403F-8F71-499B98BCCADD</key>
<dict>
Expand All @@ -402,7 +450,7 @@
<key>8C7D1146-E66D-46AF-9EDE-A63D50164F16</key>
<dict>
<key>ypos</key>
<real>140</real>
<real>240</real>
</dict>
<key>963E6413-9DDC-4642-A184-14764565F549</key>
<dict>
Expand All @@ -412,7 +460,7 @@
<key>AC920237-C64C-4EE1-AF78-C60125CC3460</key>
<dict>
<key>ypos</key>
<real>340</real>
<real>440</real>
</dict>
<key>C11961A2-A67A-4D48-8792-90AA10AD8E4C</key>
<dict>
Expand All @@ -424,8 +472,13 @@
<key>ypos</key>
<real>340</real>
</dict>
<key>FAB50204-41C8-459B-A7C4-55C2452D7033</key>
<dict>
<key>ypos</key>
<real>140</real>
</dict>
</dict>
<key>webaddress</key>
<string></string>
<string>https://github.com/jfro/ios-simulator-apps-alfred-workflow/</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion siminfo.py
Expand Up @@ -52,7 +52,8 @@ def updateCache(self):
def get_plist_key(path, key):
try:
result = check_output(['/usr/libexec/PlistBuddy', '-c', ("Print :%s" % (key)), path], stderr=STDOUT)
return result.strip()
result = result.strip()
return unicode( result, "utf-8" )
except CalledProcessError, e:
pass
return None
Expand Down Expand Up @@ -105,6 +106,7 @@ def get_app_icon(appPath):
def get_sim6_items(data_paths, device_info):
appPaths = []
for file in glob.glob(SIM_DIRAPP_SEARCH):
file = unicode( file, "utf-8" )
deviceId = get_device_id_for_app_path(file)
plistPath = join(file, 'Info.plist')
appId = get_plist_key(plistPath, 'CFBundleIdentifier')
Expand Down

0 comments on commit 153e245

Please sign in to comment.