I'm struggling with an encoding problem. After this (or a literal replacement) the encoding changes from UTF-8, UNIX LF to (Western Mac OS Roman), UNIX LF:
user-168:~ nigel$ less ~/Library/Preferences/com.apple.java.util.prefs.plist
"/Users/nige_s/Library/Preferences/com.apple.java.util.prefs.plist" may be a binary file. See it anyway?
...so you'll want to edit it with defaults or PlistBuddy. You'll need to check the plist structure first to determine the syntax you'll need, so start in Terminal with
No, because BBEdit can open, edit, and save binary text files. So you could make your changes in BBEdit -- but defaults and PlistBuddy are tools specifically made to do this job so it makes sense to use them.
The main problem is working your way through the plist's hierarchy. My plist will be different to yours so I'm not going to guess, but post or DM me the contents of the plist and I'll see if I can help.
My guess is that BBEdit infers the encoding based on the file's contents and that doing a text S'n'R on the binary completely banjaxes that. You can do it in BBEdit, but that's because it can translate the binary on opening and closing and maintain consistency.
When dealing with dictionaries you need to include the <key> line that precedes <dict> -- that's the thing that names the dictionary and allows you to target it. But there's only one <key>Goggomobil.xlf</key> in the plist so it wasn't needed this time.
"Set projectTemplates, whose parent is translator/, whose parent is /, to the value /Users/hl/Dropbox/CT/User/CT_tpl/abc_pt.xml|" (I've included the | at the end because that was in the previous entry, take it out if not needed).
"Add a key abc.xlf with the string value abc_pt.xml to dictionary templatesMap/, whose parent is translator/, whose parent is /." I've used escaped double-quotes around the string -- they're more obvious than unescaped singles (you'd end up with '") although neither are necessary here because the string contains no spaces or "funky" characters.
So, if I want to integrate this in a Keyboard Maestro, I would have to use the Shell script action, I guess? (The variable "endclient" will be inherited from the previous actions of a project creation macro.)
Yes -- and I've found after a bit of playing that you can put multiple commands into one call to PlistBuddy. It's good practice when interpolating variables to use the ${variableName} format so it's obvious to the shell (and to you!) what's the variable name and what's the text you are including it in:
I have stitched everything together now and it works. However, I have one last (?) question: how can I change the last action from Add to Set? (I've tried a lot, but I don't get there):
We need to see a) the dictionary before, and b) the dictionary after to be sure. Note that you can't Set the value of a key that doesn't exist, you must Add it.
But assuming it's already there it's like all the others -- path to key, then the value. So something like:
Even if you keep each PlistBuddy command separate, I'd urge you to include them all in one shell script (unless this is just a test and you are using KM-logic to pick between them) -- each "Execute" action takes resources to spin up a shell, so do it all in one go.
So I tried deleting the key first, and adding it then, which works. The problem, however, is that I do not know the value of the key IRL (only at first run the key will be 'tmp'). (All this exercises are because the app requires the newly added key to be the first one in the dictionary, maybe there is a way to achieve that?) com.apple.java.util.prefs.plist.zip (6.7 KB)
I have tried using '*' and '\*' to delete any existing key, but to no avail.
Here is the key: