I wrote a simple shell command and saved it as .command
. The shell command is simply: defaults write /Users/Milo/Desktop/MyPlist "My Key" "My Entry"
. The issue that I'm having is that after running that command, it messes with the order of the plist file. Normally this wouldn't be a problem, except that I wrote an application that parses the plist, and it does so according to the order of the keys in the file. I don't want to change my app just to accommodate a seemingly random ordered plist that gets returned after I run the command. How can I make the command not reorder my plist?
MacOS – Modifying .plist with shell changes .plist order
command linemacosplistterminal
Related Question
- MacOS – Automator: Change to selected directory and run shell script
- Automated screensaver configuration in command line/shell script
- MacOS – Remove .plist from /LaunchAgents
- MacOS – Problem: How to clear all remnants of random.py, random.pyc, and random.pyo that isn’t part of Python’s standard library
- MacOS – Default Browser .plist location
- Launchctl config file location
- How to gain write permission for the defaults shell command
Best Answer
The order of key value pairs within a Property List,
plist
, dictionary structure is not specified and can not be relied upon.Ideally, your application needs to parse the property list without relying on the order of the dictionary pairs.
If the order is critical to your application, consider changing the property list structure to an array of dictionaries; where each dictionary contains a single key value pair.
If you can not change your application, and the property list is formatted as XML, then you may want to investigate other command line XML manipulation tools.