Ubuntu – What happens internally when I click “Lock to launcher” in Unity

desktoplauncherunity

In the Unity desktop, when I start a GUI application, its icon appears in the launcher (if it isn't already there).

Now when I right-click this icon, I either get the option Lock to Launcher or Unlock from Launcher, depending on whether the application is already locked to the launcher or not.

My question is:
What happens under the hood, when I click one of those two options if no .desktop file exists?

Can it automatically create simple .desktop files if it can't find one, under which conditions may that happen, and where do the pinned launcher items get saved?

Best Answer

What happens if you lock/unlock an application to/from the launcher

Not sure if this answer is deep enough "under the hood", but this is what happens:

You can get the current content of the Unity Launcher by the command:

gsettings get com.canonical.Unity.Launcher favorites

It will produce a list, looking like:

['application://extras-qlequicklisteditor.desktop', 'application://gedit.desktop', 'application://gnome-terminal.desktop', 'application://nautilus.desktop', 'application://firefox.desktop', 'application://thunderbird.desktop', 'application://gnome-screenshot.desktop', 'application://dconf-editor.desktop', 'application://virtualbox.desktop', 'application://gnome-tweak-tool.desktop', 'unity://running-apps', 'unity://devices', 'unity://expo-icon']

The mentions in the list are obviously based on the names of the corresponding .desktop files.

Now when you run a GUI application, when you right- click on its icon in the launcher and choose Lock to Launcher, The currently chosen item is added to the list, while Unlock from Launcher will remove the item from the list.

Editing the Unity Launcher programmatically

Re- reading your (first) comment below your question: You can, as mentioned, get the current Launcher items by the command:

 gsettings get com.canonical.Unity.Launcher favorites

and set a possible altered list by the command:

 gsettings set com.canonical.Unity.Launcher favorites "[item1, item2, etc]"

You can then of course edit the Unity Launcher's content programmatically, as is done here.

If the application has no .desktop file

If You run a GUI application without an existing .desktop file, Unity creates a basic one locally (in ~/.local/share/applications), named after the executable (application.desktop). In the Exec= line, you will find the command you ran, to call the application.

If you would look into a .desktop file, created this way, it includes the line:

X-UnityGenerated=true

Note

As mentioned by @muru (thanks!), in a few (exceptional, as it seems) situations, Unity does not succeed to create a "missing" .desktop file of an executable. The only example I could find however was in case of Tkinter windows, which are owned by pid 0 in the output of wmctrl -lp.

Related Question