9

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.

Jorge Castro
  • 71,754
hansioux
  • 1,035
  • Have anyone tested this on Ubuntu 12.04? Its not working for me (it was working on previous versions) – saeedgnu Jun 09 '12 at 04:34
  • gsettings set com.canonical.Unity.Panel systray-whitelist "$(gsettings get com.canonical.Unity.Panel systray-whitelist | sed "s/, 'yourapp' //g" | sed "s/'yourapp' , //g" | sed -e "s/]$/, 'yourapp']/")"

    try this one, replace yourapp with what you need.

    – hansioux Jun 15 '12 at 09:22

1 Answers1

9

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.

Alin Andrei
  • 7,348
  • This new one line I came up with. This will remove any previous entries that might be the whitelist, and adding it again at the end. This is for install scripts. it's brute force but it works.

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

    – hansioux May 04 '11 at 01:43