'how to use plutil to get a value?
I need get value of "ProductVersion" and output: "15.1" I have versions of plutil, but can't get the value
plutil -key ProductVersion myfile //not working
here is the myfile content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ProductVersion</key>
<string>15.1</string>
<key>SystemImageID</key>
<string>3DD7870B-96BB-4BA1-9C54-306734147FFE</string>
<key>Version</key>
<string>Version</string>
</dict>
</dict>
</plist>
Help of plutil:
-help Print this message -full Print an exhaustive list of options -verbose Show verbose output -show Show property list data -keys List top level dictionary keys -create Create a new empty property list -key keyname Recover value for key. Multiple uses builds keypath -value value Set value for keypath -remove Remove value at keypath -type typeid Type to use while setting key. Valid types are int, float, bool, json, and string (default). Use json to define arrays and dictionaries -convert format Convert each property list file to selected format. Formats are xml1 and binary1 and json. Note that json files are saved to filename.json
Solution 1:[1]
Your plist file is malformed; the closing </dict> tag is duplicated. This needs to be fixed.
plutil as shipped with macOS 12.3 does not have a -key option (anymore), but you can use PlistBuddy:
/usr/libexec/PlistBuddy -c "Print :ProductVersion" myfile
Solution 2:[2]
This is how you get a value from a plist file using plutil on Mac OS 12.3.
plutil -extract "ProductVersion" raw myfile
In case you need to know the type of the value, you can first do:
plutil -type "ProductVersion" my file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gereon |
| Solution 2 | user3579815 |
