Мне нужно получить значение "ProductVersion" и вывести: "15.1" У меня есть версии plutil, но я не могу получить значение
plutil -key ProductVersion myfile//не работает
вот содержимое моего файла:
<?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>
Помощь 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
Ваш файл plist имеет неверный формат; закрывающий тег </dict>
дублируется. Это необходимо исправить.
plutil
, поставляемый с macOS 12.3, не имеет опции -key
(больше), но вы можете использовать PlistBuddy
:
/usr/libexec/PlistBuddy -c "Print :ProductVersion" myfile
Вот как вы получаете значение из файла plist, используя plutil в Mac OS 12.3.
plutil -extract "ProductVersion" raw myfile
Если вам нужно знать тип значения, вы можете сначала сделать:
plutil -type "ProductVersion" my file