Created
September 5, 2016 11:03
-
-
Save grahamgilbert/724e79b4a26ec172ae8b9e414e677c98 to your computer and use it in GitHub Desktop.
Writing a base64 encoded string into a plist
This file contains hidden or 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/python | |
import base64 | |
import plistlib | |
import errno | |
import os | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: | |
raise | |
def main(): | |
# This is the license. | |
license = 'abc123' | |
# Directory | |
plist_path = '/Users/Shared/Library/Preferences' | |
# File | |
plist_file = 'com.cambridgesoft.plist' | |
# make the directory if it exists | |
mkdir_p(plist_path) | |
# Encode the license to base64 | |
encoded_license = base64.b64encode(license) | |
# An ampty dict for writing (we could read this if we cared about existing data) | |
plist = {} | |
plist['license'] = encoded_license | |
# Write our file - this will wipe out anything that exists | |
plistlib.writePlist(plist, os.path.join(plist_path, plist_file)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment