How to replace a value of a key of cinnamon configuration file through the bash command line?

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Post Reply
antrrax
Level 1
Level 1
Posts: 21
Joined: Thu Sep 27, 2018 11:53 am

How to replace a value of a key of cinnamon configuration file through the bash command line?

Post by antrrax »

How to replace a value of a key of cinnamon configuration file through the bash command line?
I am trying to use the jq package. For example:

In the file ~/.cinnamon/configs/menu@cinnamon.org/0.json

how to replace "favbox-min-height" -> "value" to 405.0

I tried like this but it didn't work:
$ jq '.favbox-min-heigh.value = 405.0' '~/.cinnamon/configs/menu@cinnamon.org/0.json'
gittiest personITW
Level 8
Level 8
Posts: 2141
Joined: Tue May 28, 2019 4:27 pm

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Post by gittiest personITW »

You can use the 'sed' command.

sudo sed -i 's/OLDTEXT/NEWTEXT/g' /home/USER/.cinnamon/configs/menu@cinnamon.org/0.json

The CAPITALS are obviously what you substitute.
Be very careful as it will substitute every instance of OLDTEXT with NEWTEXT.
Best do a backup of that file first.
antrrax
Level 1
Level 1
Posts: 21
Joined: Thu Sep 27, 2018 11:53 am

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Post by antrrax »

gittiest personITW wrote:
Fri Jan 17, 2020 4:53 pm
Be very careful as it will substitute every instance of OLDTEXT with NEWTEXT.
Using sed to replace values in a json file would not be a good thing, as it could inadvertently misconfigure something.

for example, in the file ~/.cinnamon/configs/menu@cinnamon.org/0.json there are many equal [keys: values]:

Code: Select all

"value": true
If I use sed in these cases, I would have problems

So I would like to replace the values via the jq application which should better work with json
User avatar
smurphos
Level 17
Level 17
Posts: 7332
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Post by smurphos »

antrrax wrote:
Fri Jan 17, 2020 6:40 pm
So I would like to replace the values via the jq application which should better work with json
This might help - https://stackoverflow.com/questions/427 ... n-using-jq
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
antrrax
Level 1
Level 1
Posts: 21
Joined: Thu Sep 27, 2018 11:53 am

Re: How to replace a value of a key of cinnamon configuration file through the bash command line?

Post by antrrax »

For those interested in the solution:
First install the packages:
$sudo apt install jq
$sudo apt install moreutils
The Jq creates a new json with the modified value
The Sponge from the moreutils package, replaces the original json with the json created by Jq

Code: Select all

$jq '.["favbox-min-height"] |= (.value = 405.0)' ~/.cinnamon/configs/menu@cinnamon.org/0.json | sponge ~/.cinnamon/configs/menu@cinnamon.org/0.json
other expample:

Code: Select all

$jq '.["menu"] |= (.title = "test")' ~/.cinnamon/configs/menu@cinnamon.org/0.json | sponge ~/.cinnamon/configs/menu@cinnamon.org/0.json
Then restart cinnamon
Post Reply

Return to “Cinnamon”