Skip to content

Commit 183a232

Browse files
committed
Fix appinfo to work on non-running apps
1 parent 2af73bc commit 183a232

5 files changed

Lines changed: 26 additions & 30 deletions

File tree

docs/Alfred-Workflow.docset.zip

-3 Bytes
Binary file not shown.

tests/test_util.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,19 @@ def test_run_trigger():
222222

223223
def test_appinfo():
224224
"""App info for Safari."""
225-
name = u'Safari'
226-
bundleid = u'com.apple.Safari'
227-
path = u'/Applications/Safari.app'
228-
229-
info = appinfo(name)
230-
assert info is not None
231-
assert info.name == name
232-
assert info.path == path
233-
assert info.bundleid == bundleid
234-
for s in info:
235-
assert isinstance(s, unicode)
225+
for name, bundleid, path in [
226+
(u'Safari', u'com.apple.Safari', u'/Applications/Safari.app'),
227+
(u'Digital Color Meter', u'com.apple.DigitalColorMeter',
228+
u'/Applications/Utilities/Digital Color Meter.app'),
229+
]:
230+
231+
info = appinfo(name)
232+
assert info is not None
233+
assert info.name == name
234+
assert info.path == path
235+
assert info.bundleid == bundleid
236+
for s in info:
237+
assert isinstance(s, unicode)
236238

237239
# Non-existant app
238240
info = appinfo("Big, Hairy Man's Special Breakfast Pants")

workflow/util.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,21 @@ def appinfo(name):
232232
Returns:
233233
AppInfo: :class:`AppInfo` tuple or ``None`` if app isn't found.
234234
"""
235-
cmd = ['/usr/bin/lsappinfo', 'info', name]
236-
output = run_command(cmd).strip()
237-
if not output: # Application isn't installed
238-
return None
239-
240-
path = bid = None
241-
for line in output.split('\n'):
242-
line = line.strip()
243-
if '=' in line:
244-
k, v = line.split('=', 1)
245-
v = v.strip('"')
235+
cmd = ['mdfind', '-onlyin', '/',
236+
'(kMDItemContentTypeTree == com.apple.application &&'
237+
'(kMDItemDisplayName == "{0}" || kMDItemFSName == "{0}.app"))'
238+
.format(name)]
246239

247-
if k == 'bundleID':
248-
bid = v
249-
elif k == 'bundle path':
250-
path = v.rstrip('/')
240+
path = run_command(cmd).strip()
241+
if not path:
242+
return None
251243

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

255-
return None # pragma: no cover
249+
return AppInfo(unicodify(name), unicodify(path), unicodify(bid))
256250

257251

258252
@contextmanager

workflow/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.31
1+
1.32

0 commit comments

Comments
 (0)