plists issue with catalina

jmcconathy
New Contributor III

I create a custom plist file, to save some script execution details, on a network drive which I have been creating/modifying with the defaults command. I haven't had any issue with this over several macos versions.

Catalina appears to not be creating the file on my network drive, error "Could not write domain...". It creates the file just fine on the local disk.

I thought I would create the plist file locally and copy it over to the network location. The copy works, but then Catalina cannot read the file copied using defaults. It says the 'Domain ... does not exist'. If i run the plutil -lint command on the file, it says 'OK'. If i copy the plist file locally even, it wont read the copied file.

I have done all actions in terminal using the same account. Terminal has access to NetworkVolumes.

Wondering if anyone can recreate this or know how to workaround? Id rather not switch to something other than plist yet.

4 REPLIES 4

sdagley
Esteemed Contributor II

ryan_ball
Valued Contributor

I have much better success using /usr/bin/plutil and /usr/libexec/PlistBuddy for creation/reading of plist files. Also, using defaults in scripts may become problematic at some point:
Source - man defaults

WARNING: The defaults command will be changed in an upcoming major release to only operate on preferences domains. General plist manipulation utilities will be folded into a different command-line program.

Which command-line program are they referring to? Probably one of the two I mentioned.

jmcconathy
New Contributor III

@sdagley Seems likely, I am suspecting the catalina security changes to be the culprit.

@ryan.ball I started looking into those, but I haven't found a way yet to read the values back in to my script later using plutil. The xml it returns isnt very friendly.

ryan_ball
Valued Contributor

@jmcconathy Here is an example of writing/reading a plist using PlistBuddy:

#!/bin/bash

# This is the plist to create
plist="$HOME/Downloads/com.contoso.settings.plist"

# String
sampleStringValue="this is a string"

# Boolean
sampleBooleanValue="true"

# Array
sampleArrayValues=(
    "Element1"
    "Element2"
    "Element3"
)

# Clear plist if it exists
[[ -e "$plist" ]] && /usr/libexec/PlistBuddy -c Clear "$plist" &> /dev/null

# Create the string and bool keys
/usr/libexec/PlistBuddy -c "Add :StringSetting string $sampleStringValue" "$plist"
/usr/libexec/PlistBuddy -c "Add :BooleanSetting bool $sampleBooleanValue" "$plist"

# Create the array and elements using the index to increment element placement
/usr/libexec/PlistBuddy -c "Add :ArraySetting array" "$plist"
index="0"
for element in "${sampleArrayValues[@]}"; do
    /usr/bin/plutil -insert "ArraySetting.$index" -string "$element" "$plist"
    ((index++))
done

# Convert the plist to XML format so you can read it easier
plutil -convert xml1 "$plist"

# Print out the details of the plist
echo " "
echo "StringSetting: $(/usr/libexec/PlistBuddy -c "Print:StringSetting" "$plist")"
echo "BooleanSetting: $(/usr/libexec/PlistBuddy -c "Print:BooleanSetting" "$plist")"
echo "ArraySetting:"
/usr/libexec/PlistBuddy -c "Print:ArraySetting" "$plist" | sed -e '1d;$d' | sed -e 's/^[ 	]*//'
echo " "

# To set a variable as the value of one of the keys
variable=$(/usr/libexec/PlistBuddy -c "Print:StringSetting" "$plist")
echo "$variable"

exit 0