-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandlers-list.py
executable file
·103 lines (84 loc) · 3.01 KB
/
handlers-list.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
import os
import re
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-F", "--full-path", action="store_true",
dest="fullpath", default=False,
help="Include full path of the Application instead of the last component.")
parser.add_option("-p", "--pretty", action="store_true",
dest="pretty", default=False,
help="Display pretty printed output instead of JSON.")
parser.add_option("-a", "--all", action="store_true",
dest="all", default=False,
help="Include all handlers, not just URL handlers.")
(options, args) = parser.parse_args()
dump = os.popen("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump")
# bundle id: 53140
# path: /Applications/Firefox.app
# name: Firefox
# ...
# claim id: 36428
# name: file URL
# rank: Default
# reqCaps:
# roles: Viewer
# flags: url-type
# icon:
# bindings: file:
rexps = [
re.compile('^\s*(bundle)\s*id:\s*(\d*)'),
re.compile('^\s*(path):\s*(.*)'),
re.compile('^\s*(name):\s*(.*)'),
re.compile('^\s*(claim)\s*id:\s*(\d*)'),
re.compile('^\s*(flags):\s*(.*)'),
re.compile('^\s*(bindings):\s*(.*)')
]
handlers = {}
bundle = ""
appname = ""
apppath = ""
for line in dump.readlines():
for rexp in rexps:
m = rexp.match(line)
if not m:
continue
key = m.group(1)
value = m.group(2)
if key == "bundle":
if bundle != value:
bundle = value
name = ""
path = ""
if key == "name" and not name:
name = value
if key == "path" and not path:
if options.fullpath:
path = value
else:
path = os.path.basename(os.path.normpath(value))
if key == "flags":
rawflags = value
if key == "bindings":
for binding in [x for x in value.split(",") if x]:
id = binding.lstrip()
flags = [x for x in rawflags.split(" ") if x]
if (not options.all) and ("url-type" not in flags):
continue
application = {}
application['name'] = name
application['path'] = path
application['flags'] = flags
if id not in handlers:
handlers[id] = {}
if 'apps' not in handlers[id]:
handlers[id]['apps'] = []
handlers[id]['apps'].append(application)
dump.close()
if options.pretty:
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(handlers)
else:
import json
print(json.dumps(handlers, indent=4, sort_keys=True))