Created
May 16, 2019 17:57
-
-
Save 9999years/8b6f92c10b52d6ea0e6cc0d2aba1d482 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 | |
# 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