Skip to content

Commit

Permalink
Fix appinfo to work on non-running apps
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Dec 18, 2017
1 parent 2af73bc commit 183a232
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
Binary file not shown.
Binary file modified docs/Alfred-Workflow.docset.zip
Binary file not shown.
24 changes: 13 additions & 11 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,19 @@ def test_run_trigger():

def test_appinfo():
"""App info for Safari."""
name = u'Safari'
bundleid = u'com.apple.Safari'
path = u'/Applications/Safari.app'

info = appinfo(name)
assert info is not None
assert info.name == name
assert info.path == path
assert info.bundleid == bundleid
for s in info:
assert isinstance(s, unicode)
for name, bundleid, path in [
(u'Safari', u'com.apple.Safari', u'/Applications/Safari.app'),
(u'Digital Color Meter', u'com.apple.DigitalColorMeter',
u'/Applications/Utilities/Digital Color Meter.app'),
]:

info = appinfo(name)
assert info is not None
assert info.name == name
assert info.path == path
assert info.bundleid == bundleid
for s in info:
assert isinstance(s, unicode)

# Non-existant app
info = appinfo("Big, Hairy Man's Special Breakfast Pants")
Expand Down
30 changes: 12 additions & 18 deletions workflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,21 @@ def appinfo(name):
Returns:
AppInfo: :class:`AppInfo` tuple or ``None`` if app isn't found.
"""
cmd = ['/usr/bin/lsappinfo', 'info', name]
output = run_command(cmd).strip()
if not output: # Application isn't installed
return None

path = bid = None
for line in output.split('\n'):
line = line.strip()
if '=' in line:
k, v = line.split('=', 1)
v = v.strip('"')
cmd = ['mdfind', '-onlyin', '/',
'(kMDItemContentTypeTree == com.apple.application &&'
'(kMDItemDisplayName == "{0}" || kMDItemFSName == "{0}.app"))'
.format(name)]

if k == 'bundleID':
bid = v
elif k == 'bundle path':
path = v.rstrip('/')
path = run_command(cmd).strip()
if not path:
return None

if bid and path:
return AppInfo(*[unicodify(s) for s in (name, path, bid)])
cmd = ['mdls', '-raw', '-name', 'kMDItemCFBundleIdentifier', path]
bid = run_command(cmd).strip()
if not bid: # pragma: no cover
return None

return None # pragma: no cover
return AppInfo(unicodify(name), unicodify(path), unicodify(bid))


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion workflow/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.31
1.32

0 comments on commit 183a232

Please sign in to comment.