com.apple.xyz.plist - replace value - not set key - possbile? I've looked into using PlistBuddy and plutil but most examples such as: 

How do I replace a value in an plist array using plutil?

seem to suggest setting the value of a key, which is not the case here. 

I want to modify a value I do not know exists or not. See, I don't know what the key is. I want to automate it. 

So if you can search for a value, get the value and key then I could possibly use the above to set a new value on the key. 

But i have not figured out a way to do that. 

Do you know? Preferably in Bash.
######################################## BASH LIB #######################################
bash.string.replace() {
        local text="$1" find="$2" replace="$3";

        echo "${text}" | while IFS= read -r line; do 
                printf '%s\n' "${line//"$find"/$replace}"; 
        done 
}
######################################## BASH LIB #######################################

######################################## APPLE LIB ######################################
apple.plist.read() {
        local filepath="${1}"

        defaults read "${filepath}"                
}
apple.plist.convert.to.xml() {
        local filepath="${1}" tmp="${2}"

        # If second argument is passed, then we save the conversion to a new file rather than write over the original
        if [[ "${tmp}" == "true" ]]; then
            tmp="/tmp${filepath}"
        fi 

        if [[ "${tmp}" != "" ]]; then
            bash.cp "${filepath}" "${tmp}"

            filepath="${tmp}"
        fi

        plutil -convert xml1 "${filepath}"

        # We also output the content which can be supressed if desired by caller
        cat "${filepath}"                
}
apple.plist.convert.to.binary() {
        local filepath="${1}"

        plutil -convert binary1 "${filepath}"                
}
apple.plist.write() {
        local filepath="$1" text="$2"

        echo "${text}" &gt; "${filepath}"

        apple.plist.convert.to.binary "${filepath}" # Not sure if this step is neccessary, if xml representation is enough. Not verified or tested without. 
}
apple.plist.read.search.replace.write() {
        local file="${1}" search="${2}" replacement="${3}"

        local updated=$(bash.string.replace "$(apple.plist.read "${file}")" "${search}" "${replacement}")

        apple.plist.write "${file}" "${updated}"
}
######################################## APPLE LIB ######################################


######################################## EXAMPLE ##################################
my.test.1() {
    apple.plist.read.search.replace.write "/tmp/com.apple.finder.plist" "/Users/" "/Home/"
}
######################################## EXAMPLE ##################################


Basically we call the function plist.read.search.replace.write with file arguments and what to replace which will read it to text, then we perform a replacement on that text, and then write that text back using plist.write which will also convert it from xml (which it will be) to binary using plutil -convert xml1 "/path/to/file". 

Rather than read using defaults read "..." we could in theory instad use plutil convert to xml but likely more expensive.