9

Although there are several posts on the Internet on the subject, I did not find a solution yet:
my goal is to find a command that adds an icon (.desktop file) to the Unity launcher and shows it immediately. when I open dconf-editor (desktop > unity > launcher) and I add an item to the favorites list, it shows at once in the launcher, so my idea is that it must be possible to do the same thing by command. The solutions I found so far on the Internet do not do the job.

I need to do it by command, to use in a quicklist editor I am working on.

You would make someone unbelievably happy if you could help out

0

2 Answers 2

12

You can act on dconf also with gsettings tool.

gsettings set com.canonical.Unity.Launcher favorites "$(gsettings get com.canonical.Unity.Launcher favorites | sed "s/, *'yourapp' *//g" | sed "s/'yourapp' *, *//g" | sed -e "s/]$/, 'yourapp']/")"
3
  • @Jacob, @jasmines This does not work in a chroot environment. gsettings says twice ** (process:10439): WARNING **: The connection is closed, but does not change the value (get still returns the old one). Any hint about this? Isn't this value stored in a plain text file somewhere? Oct 4, 2012 at 7:18
  • @Didier Trosset, You cannot run gsettings as root -- it must be run as your userid.
    – user220845
    Nov 30, 2013 at 19:15
  • @Pete Howell: Why not ? Works perfectly on my machine.
    – WitchCraft
    Dec 6, 2013 at 6:27
2

The accepted answer is alright, but cumbersome due to use of sed and lots of escape sequences. The bellow pythonic solution is much cleaner, and allows simply specify what .desktop file you want appended, and optionally you can specify a position on the launcher.

For example,

python launcher_append_item.py sakura.desktop 3  

would place sakura as 4th icon (because list indexes start with 0). Running simply

python launcher_append_item.py sakura.desktop  

would append the icon to the list.

For further thought, one could even add an option for replacing a specific item on launcher with some other item. But that's an exercise for future contemplation :)

source code

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio,Gtk
import dbus
import sys

def gsettings_get(schema,path,key):
    if path is None:
        gsettings = Gio.Settings.new(schema)
    else:
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.get_value(key)

def gsettings_set(schema,path,key,value):
    if path is None:
        gsettings = Gio.Settings.new(schema)
    else:
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.set_strv(key,value)


current_list = list(gsettings_get('com.canonical.Unity.Launcher',None,'favorites'))

if sys.argv[2]:
   current_list.insert(int(sys.argv[2]),'application://' + sys.argv[1])
else:
   current_list.append(  'application://' + sys.argv[1]  )

gsettings_set( 'com.canonical.Unity.Launcher', None, 'favorites',current_list  )
1
  • Thanks a lot! I realize the question is a dupe of one I answered later. Jul 23, 2016 at 9:05

Not the answer you're looking for? Browse other questions tagged .