I'm writing a bash script that modifies a program, then adds an icon to the unity launcher. Although I've created the .desktop file in /usr/share/applications, I can't see a way to programmatically add the shortcut to the launcher.
Asked
Active
Viewed 2,287 times
3
-
see also http://askubuntu.com/a/761021/295286 or http://askubuntu.com/a/829228/295286 – Sergiy Kolodyazhnyy Feb 16 '17 at 14:28
1 Answers
4
- First get the list of applications from the launcher:
$ gsettings get com.canonical.Unity.Launcher favorites
Make an array of the items.
Then have your install script add your application to the array
Then have your script add the items from the created array to this command with item comma separated:
$ gsettings set com.canonical.Unity.Launcher favorites "['app1','app2','app3','your program.desktop']"
The app# is the applications from the array that you are including in your installer script.
Replace your program with the name of the *.desktop
launcher you created.
Update:
The procedure is listed above.
This is a command line that will append your application to the launcher
gsettings set com.canonical.Unity.Launcher favorites "$(gsettings get com.canonical.Unity.Launcher favorites | sed "s/]/,'Your Program.desktop']/")"
Add the above commandline to your install script. Replace the bold Your Program.desktop with the program you created. This will not clobber what your current icons. It'll append.

L. D. James
- 25,036
-
-
You have that error because there isn't a key
favourites
. I understand dependent on the language dialect there's a difference in spelling. But the required keyname in Ubuntu isfavorites
. Try copying and pasting the command. Then change only what is highlighted in bold. – L. D. James Feb 16 '17 at 13:05 -
It's not clear to me what you're saying about adding one... Are you saying adding an Icon for the desktop launcher, or are you saying adding an icon to the Ubuntu Launcher. The command adds a created desktop launcher, which the user has created and placed in his applications folder, to Ubuntu's side bar launcher. It won't affect the icon. Whatever icon is already included in the *.desktop file the user has create, will app in the launcher. The user call manually right click and stick a applicaton to the launcher. This command will allow the OP's installer script to do this. – L. D. James Feb 16 '17 at 14:10
-
2Simply:
gsettings set com.canonical.Unity.Launcher favorites "['your program.desktop']"
sets the launcher to"['your program.desktop']"
. It removes all other icons, which definitely is not the intention of OP. Did you try the command? – Jacob Vlijm Feb 16 '17 at 14:12 -
Now I see what you are saying... Thanks. I'll fix the answer. Your refernce to single icon to the launcher. – L. D. James Feb 16 '17 at 14:16
-
-
@L.D.James I get it now, sorry that was a really silly error. Can I create an array variable and add my app to it programmatically? Or do I have to take everything out of the array, add my app to them, and create a new array? – Wolfish Feb 16 '17 at 16:31
-
Sorry I didn't write the script yet. I'll write a crude example and post it ASAP. But the gist is to first grab all the items that are there with the get argument. Place them in an array and include your desktop item in the array, then read the array into the "[]" field with entries comma separated. – L. D. James Feb 16 '17 at 16:35