forked from bpinto/alfred-extension-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (33 loc) · 1.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# jmjeong, 2013/3/25
import alfred
import subprocess
import re
import os
import plistlib
from uuid import uuid4
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def process():
dirname = os.path.dirname(os.path.abspath('.'))
dirs = [f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, f))]
results = []
for (idx,d) in enumerate(dirs):
try:
print os.path.join(dirname, d, 'settings.plist')
plist = plistlib.readPlist(os.path.join(dirname, d, 'info.plist'))
except:
continue
title = plist['name']
disabled = plist.get('disabled', None)
createdby = plist['createdby']
displayTitle = title + (' - disabled' if disabled else '')
results.append({'title': displayTitle, 'createdby' : createdby, 'disabled' : disabled, 'directory' : d})
results = sorted(results, key=lambda a: a['title'].lower())
resultsData = [alfred.Item(title=f['title'], subtitle=' by ' + (f['createdby'] or "[noinfo]"), attributes = {'uid':uuid4(), 'arg':os.path.join(dirname,f['directory'])}, icon=os.path.join(dirname, f['directory'], u"icon.png")) for f in results]
alfred.write(alfred.xml(resultsData, maxresults=None))
if __name__ == '__main__':
process()