Search code examples
gnomelauncherubuntu-18.04gnome-3

Gnome 1804 - Add .desktop to launcher via commandline


I'm trying to script adding x.desktop items to the gnome launcher in 18.04.
In unity (16.04) you can use: gsettings set com.canonical.Unity.Launcher favorites XYZ but I can't work out the equivalent (if it even exists) in gnome. I've found gsettings of: org.gnome.gnome-panel.launcher:/


Solution

  • Right, I worked it out so I figured I'd share this back.

    For gnome (eg ubuntu 18.04), the following script will add an existing desktop file to favourites:

    application="'${1}.desktop'"
    favourites="/org/gnome/shell/favorite-apps"
    dconf write ${favourites} \
      "$(dconf read ${favourites} \
      | sed "s/, ${application}//g" \
      | sed "s/${application}//g" \
      | sed -e "s/]$/, ${application}]/")"
    

    For Unity (eg ubuntu 16.04), the following script will add an existing desktop file to favourites:

    application="'${1}.desktop'"
    favourites="/com/canonical/unity/launcher/favorites"
    dconf write ${favourites} \
      "$(dconf read ${favourites} \
      | sed "s/, ${application}//g" \
      | sed "s/${application}//g" \
      | sed -e "s/]$/, ${application}]/")"
    

    Scripts usage as follows:

    ./add_favourite.sh google-chrome