-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (38 loc) · 1.38 KB
/
app.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
from plistlib import readPlist
from AppKit import NSWorkspace
from sys import stdout
from sys import argv
from xml.parsers.expat import ExpatError
def binary_plist_to_file_obj(filename):
"Pipe the binary plist through plutil and return as file object"
from subprocess import Popen, PIPE
from StringIO import StringIO
with open(filename, "rb") as f:
content = f.read()
args = ["plutil", "-convert", "xml1", "-o", "-", "--", "-"]
p = Popen(args, stdin=PIPE, stdout=PIPE)
out, err = p.communicate(content)
return StringIO(out)
path = ''
if len(argv) > 1:
path = argv[1]
if path == '':
path = NSWorkspace.sharedWorkspace().activeApplication().get('NSApplicationPath')
path += '/Contents/Info.plist'
try:
info = readPlist(path)
except(ExpatError): # binary plist
info = readPlist(binary_plist_to_file_obj(path))
appName = info.get('CFBundleExecutable')
if 'CFBundleDisplayName' in info:
appName = info.get('CFBundleDisplayName')
elif 'CFBundleName' in info:
appName = info.get('CFBundleName')
appVersion = info.get('CFBundleVersion')
appShortVersion = info.get('CFBundleShortVersionString')
if appShortVersion and appVersion:
if appVersion != appShortVersion:
appVersion = appShortVersion + ' (' + appVersion + ')'
elif not appVersion and appShortVersion:
appVersion = appShortVersion
stdout.write(appName + ' v' + appVersion)