-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
apple-device-names
executable file
·34 lines (28 loc) · 1.02 KB
/
apple-device-names
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
#!/usr/bin/env python3
import re, json
from glob import glob
from subprocess import Popen, PIPE
mapping = {}
def parse_info(filename):
p = Popen([
'plutil',
'-convert', 'json',
f,
'-o', '-'
], stdout=PIPE)
data = json.load(p.stdout)
for item in data['UTExportedTypeDeclarations']:
if 'UTTypeTagSpecification' not in item: continue
for code in item['UTTypeTagSpecification']['com.apple.device-model-code']:
if re.match(r'^[a-zA-Z]+\d+,\d+$', code):
name = item['UTTypeDescription']
name = re.sub(r'Model A?\d+(, A?\d+)*', '', name)
name = re.sub(r' *?\)', ')', name)
name = re.sub(r' \(\)', '', name)
mapping[code] = name
for f in glob('/System/Library/CoreServices/CoreTypes.bundle/Contents/Library/MobileDevices*.bundle/Contents/Info.plist'):
parse_info(f)
print('let appleDeviceNames = [')
for code, name in mapping.items():
print(f' "{code}": "{name}",')
print(']')