Guisettings.xml overwritten at startup

I am trying to automate a setup. One of the steps involves modifying guisettings.xml. Somehow this file is overwritten at startup.

I have read in the kodi forums that kodi writes this file at shuitdown. So I stop mediacenter, write the file and start mediacenter. But somehow guisettings.xml is overwritten at statup. The setting is again at the previous value and the timestamp of the file is at startup time.

This script:

systemctl stop mediacenter
file="/home/osmc/.kodi/userdata/guisettings.xml"
search="<setting id=\"addons.unknownsources\" default=\"true\">false"
replace="<setting id=\"addons.unknownsources\" default=\"true\">true"
sed -i "s/$search/$replace/g" $file
grep addons.unknownsources $file
systemctl start mediacenter
sleep 5
grep addons.unknownsources $file

Outputs:

    <setting id="addons.unknownsources" default="true">true</setting>
    <setting id="addons.unknownsources" default="true">false</setting>

How can I change values in guisettings.xml with a script?

Works for me. Try a bit of sleep before the sed in case there’s a disk cache delay.

Oops. Misread the output.

The guisettings.xml is not tolerant to invalid data and so it’s replacing the invalid data you put in it with default values. If you had checked the file after manually setting that parameter you would find the two valid entries are…

<setting id="addons.unknownsources">true</setting>
or
<setting id="addons.unknownsources" default="true">false</setting>

1 Like

@darwindesign This works! I did not expect that <setting id="addons.unknownsources" default="true">true</setting> would be invalid. Thank you for the clarification!

Use a tool like XMLStartlet to manipulate XML files via the command line.

Thank you for the tip.

The XML was valid XML, that was not the problem. The problem was that when one specifies a value that equals the default attribute, kodi considers this to be invalid for some reason.