This utility is designed to convert Apple plist
files to yaml
, or yaml
files to plist
. I/O is from regular files.
It can also convert json
files to plist
.
The python ruamel.yaml
module is required, which is not installed by default on Macs. You can install it with pip
, which you may also need to install first. A few other things need to be updated for ruamel to install:
python -m ensurepip --user
python -m pip install -U pip setuptools wheel ruamel.yaml<0.18.0 --user
If you do not pre-install ruamel.yaml
, setup.py will do it for you.
git clone git@github.com:grahampugh/plist-yaml-plist && cd plist-yaml-plist
python -m pip install .
A github ssh key is required to run pip install -r requirements.txt
.
requirements.txt:
-e git+ssh://git@github.com/grahampugh/plist-yaml-plist#egg=plistyamlplist
A single command can be used to convert from plist to yaml or from yaml to plist. This depends on the file suffices being predictable:
plistyamlplist -h
Usage: ./plistyamlplist.py <input-file> [<output-file>]
You can supply the input-file as a glob (*.yaml
or *.json
) to convert an entire directory or subset of yaml
or json
files. This currently only work for converting from yaml to plist. Note that you have to escape the glob, i.e. write as plistyamlplist /path/to/\*.yaml
. Or, just supply a folder. The folder must be _YAML
or YAML
or a subfolder of one of these.
Otherwise, each file can be used individually:
./plist_yaml.py -h
Usage: plist-yaml.py <input-file> [<output-file>]
./yaml_plist.py -h
Usage: yaml-plist.py <input-file> [<output-file>]
Notes:
- With
plistyamlplist.py
, if you do not specify anoutput-file
value, the script determines if theinput-file
is aplist
,yaml
orjson
file. If aplist
file, theinput-file
name will be appended with.yaml
for the output file. If ayaml
orjson
file, the output file name will be theinput-file
name with.yaml
orjson
removed. - With
plist_yaml.py
, if you do not specify anoutput-file
value, theinput-file
name will be appended with.yaml
for the output file. - With
yaml_plist.py
, if you do not specify anoutput-file
value, and theinput-file
name ends with.yaml
, the output file name will be theinput-file
name with.yaml
removed. - With
plist_yaml.py
, you may have to first convert a binary plist to text format usingplutil
.
To convert a plist file to yaml:
plutil -convert xml1 ~/Library/Preferences/com.something.plist
./plistyamlplist.py ~/Library/Preferences/com.something.plist ~/Downloads/com.something.yaml
./plistyamlplist.py ~/Library/Preferences/com.something.plist
# this will output to `~/Library/Preferences/com.something.plist.yaml'
To convert a yaml file to a plist file:
./plistyamlplist.py ~/Downloads/com.something.yaml ~/Downloads/com.something.plist
$ ./plistyamlplist.py ~/Downloads/com.something.plist.yaml
# this will output to `~/Downloads/com.something.plist'
If you have a folder named YAML
/_YAML
, or JSON
/_JSON
, in your path, and you do not supply a destination, the script will determine if a corresponding folder exists in the path without YAML
/JSON
. For example, consider the following file:
/Users/myuser/gitrepo/YAML/product/com.something.plist.yaml
If the folder /Users/myuser/gitrepo/product
exists, the converted file will be created/overwritten at:
/Users/myuser/gitrepo/product/com.something.plist
If the above folder does not exist, you will be prompted to create it.
If there is no YAML
/JSON
folder in the path, the converted file will be placed in the same folder.
If you convert an AutoPkg recipe from plist
to yaml
, the following formatting is carried out:
- The different process dictionaries are ordered by Processor, Comment, Arguments (python3 only).
- The Input dictionary is ordered such that NAME is always at the top (python3 only).
- The items are ordered thus: Comment, Description, Identifier, ParentRecipe, MinimumVersion, Input, Process (python3 only).
- Blank lines are added for human readability. Specifically these are added above Input and Process dictionaries, and between each Processor dictionary.
You can also carry out reformatting of existing yaml
recipes using the yaml_tidy.py
script, or using plistyamlplist
as in the following examples:
-
Convert an AutoPkg recipe to yaml format:
plistyamlplist /path/to/SomeRecipe.recipe
-
Reformat a single
yaml
-based recipe:plistyamlplist /path/to/SomeRecipe.recipe.yaml --tidy
-
Reformat a an entire folder structure containing
yaml
-based recipes:plistyamlplist /path/to/YAML/ --tidy # this will process all .recipe.yaml files in the folders within /path/to/YAML plistyamlplist /path/to/\_YAML/ --tidy # this will process all .recipe.yaml files in the folders within /path/to/_YAML plistyamlplist /path/to/YAML/subfolder/ --tidy # this will process all .recipe.yaml files in the folders within /path/to/_YAML/subfolder
Elements of these scripts come from: