Skip to content

Instantly share code, notes, and snippets.

@9999years
Created May 16, 2019 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9999years/8b6f92c10b52d6ea0e6cc0d2aba1d482 to your computer and use it in GitHub Desktop.
Save 9999years/8b6f92c10b52d6ea0e6cc0d2aba1d482 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
# Short program to read macOS plist files and output JSON; useful for manipulating / viewing the JSON with a tool like jq.
import fileinput
import json
import plistlib
def plist_to_json(plist):
return json.dumps(plistlib.loads(plist))
def lines_to_json(plist_lines):
return plist_to_json(b''.join(plist_lines))
def main():
lines = []
for line in fileinput.input(mode='rb'):
if lines and fileinput.isfirstline():
print(lines_to_json(lines))
lines = []
lines.append(line)
if lines:
print(lines_to_json(lines))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment