Ubuntu – One line command for adding new items to com.canonical.Unity.Panel systray-whitelist

command linegsettingssedunity

This is more of a how to use command line instruction question more than how to add items to the Unity notification panel.

I have to have a one line CLI to add a new item to com.canonical.Unity.Panel systray-whitelist.

Standard procedure for doing so is:

sudo gsettings get com.canonical.Unity.Panel systray-whitelist

We get

['JavaEmbeddedFrame', 'Wine', 'Skype']

Then we do the second command

sudo gsettings set com.canonical.Unity.Panel systray-whitelist "['JavaEmbeddedFrame', 'Wine', 'Skype', 'shutter']"

While that's great and all, it requires people to copy and paste the result from the first line, and for a script i am writing I want to do it in one command.

So far this is what I have:

sudo gsettings set com.canonical.Unity.Panel systray-whitelist | gsettings get com.canonical.Unity.Panel systray-whitelist | sed -e "s/']$/,'shutter']/" | awk 'NF{print "\"" $0 "\""}'

I think I am missing something.

Firstly, I am not sure if I am piping the string into gsettings set function correctly.
Secondly, while I think I am parsing the output from gsettings get function correctly, I wouldn't figure out a way to add the " " around the modified result using sed, so I had to pipe another awk command into this mess.

Thanks to anyone that helps.

Best Answer

After hitting error after error, I finally figured why it didn't accept the quotes. You can simply place the quotes around the actual variable, no need to enter them in the actual command.

This will work:

gsettings set com.canonical.Unity.Panel systray-whitelist "$(gsettings get com.canonical.Unity.Panel systray-whitelist | sed -e "s/]$/, 'shutter']/")"

(Also, you need to remove the ' in sed -e "s/']$/ in your example for this to work).

Later edit: by the way, don't run gsettings with sudo... it won't work.