Last active
June 4, 2019 20:42
-
-
Save SamusAranX/ba656bbdf89ff8812f043bda67bc520a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#-*- coding: utf-8 -*- | |
# usage: Put a bunch of fonts into a folder named like the font next to this script | |
# Do this: ./fontprofile.py "<FONT NAME>" | |
# There should now be a <FONT NAME>.mobileconfig file in the script's folder | |
# Don't pack too many fonts at once, iOS will complain if the file is too large | |
# The maximum file limit seems to be different on every iOS device, so YMMV | |
# Also, there are some font files (mostly exotic ones) that this script has problems with | |
# I think this is an encoding problem, but it mostly shouldn't be a problem | |
import plistlib | |
import uuid | |
import os | |
import argparse | |
import glob | |
def main(): | |
parser = argparse.ArgumentParser(description="Goes through a folder of fonts and generates a .mobileconfig file") | |
parser.add_argument("folder", nargs="?", type=str) | |
args = parser.parse_args() | |
profile_name = os.path.basename(os.path.abspath(args.folder)) | |
print(profile_name) | |
fonts = glob.glob(os.path.join(os.path.abspath(args.folder), "*.ttf")) + glob.glob(os.path.join(os.path.abspath(args.folder), "*.otf")) | |
profile_uuid = uuid.uuid4().urn[9:].upper() | |
profile = { | |
"PayloadContent": [], | |
"PayloadDescription": "Adds {0} to the device".format(profile_name), | |
"PayloadDisplayName": profile_name, | |
"PayloadIdentifier": "flyingace.local." + profile_uuid, | |
"PayloadRemovalDisallowed": False, | |
"PayloadType": "Configuration", | |
"PayloadUUID": profile_uuid, | |
"PayloadVersion": 1 | |
} | |
for f in fonts: | |
with open(f, "rb") as font: | |
fontuuid = uuid.uuid4().urn[9:].upper() | |
filename = os.path.basename(os.path.abspath(f)) | |
fontdata = plistlib.Data(font.read()) | |
fontdict = { | |
"Font": fontdata, | |
"Name": filename, | |
"PayloadDescription": "Configures Font settings", | |
"PayloadDisplayName": "Fonts", | |
"PayloadIdentifier": "com.apple.font." + fontuuid, | |
"PayloadType": "com.apple.font", | |
"PayloadUUID": fontuuid, | |
"PayloadVersion": 1 | |
} | |
profile["PayloadContent"].append(fontdict) | |
with open("{0}.mobileconfig".format(profile_name), "wb") as mobileconfig: | |
plistlib.dump(profile, mobileconfig) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment