Estoy tratando de crear una plist usando "escritura predeterminada", desafortunadamente no puedo usar Plutil ni ninguna otra utilidad.
Datos hexadecimales: 62706c69 73743030 d4010203
Este es el plist que necesito crear
<?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>Architectures for arm64</key>
<dict>
<key>org.my.test</key>
<array>
<data>
YnBsaXN0MDDUAQID
</data>
<string>x86_64</string>
</array>
</dict>
</dict>
</plist>
Estoy usando esta sintaxis:
defaults write ~/Desktop/org.my.test '{"Architectures for arm64" = {org.my.test = (-data <62706c69 73743030 d4010203>, "x86_64");};}'
y recibo el error: 2021-06-26 09:21:09.280 defaults[27260:1348922] No se pudo analizar: {"Architectures for arm64" = {org.my.test = (-data <62706c69 73743030 d4010203> , "x86_64");};}. Intente citarlo con comillas simples.
No puedo averiguar dónde debo poner las comillas simples
¿Alguien puede ayudarme por favor?
-data
es un parámetro para defaults
cuando se escribe un solo valor de datos.
Está escribiendo una lista completa de propiedades de una sola vez, así que no incluya este argumento como parte de la cadena de la lista de propiedades. Elimine -data
de su comando y funciona bien escribiendo la cadena completa como el contenido del archivo de lista de propiedades.
Al escribir una lista completa de propiedades, los datos se codifican como hexadecimales entre paréntesis angulares como lo ha hecho.
También podrías usar defaults import
.
Eso le permite especificar los datos como el mismo texto xml que está mostrando en su pregunta. El comando inverso, para ver los resultados, es defaults export -
.
Si busca valores predeterminados en la página de manual, tiene opciones para crear diccionarios y matrices, y agregar elementos a matrices existentes y pares de claves a diccionarios existentes.
-array Allows the user to specify an array as the value for the given preference key:
defaults write somedomain preferenceKey -array element1 element2 element3
The specified array overwrites the value of the key if the key was present at the time of the write. If
the key was not present, it is created with the new value.
-array-add Allows the user to add new elements to the end of an array for a key which has an array as its value.
Usage is the same as -array above. If the key was not present, it is created with the specified array as
its value.
-dict Allows the user to add a dictionary to the defaults database for a domain. Keys and values are speci-
fied in order:
defaults write somedomain preferenceKey -dict key1 value1 key2 value2
The specified dictionary overwrites the value of the key if the key was present at the time of the
write. If the key was not present, it is created with the new value.
-dict-add Allows the user to add new key/value pairs to a dictionary for a key which has a dictionary as its
value. Usage is the same as -dict above. If the key was not present, it is created with the specified
dictionary as its value.
Un enfoque estructural puede funcionar mejor que intentar meterlo todo con puntuación.
-array
/ -array-add
son las opciones correctas, pero ¿cómo se pueden agregar algunos datos? El fragmento de la página del manual solo dice element1
. ¿Quizás esta respuesta podría explicar qué element1
usar para agregar datos a una matriz con esas opciones?
sin ladera
dimitrios