Is there any way to automatically add icons for an application when a package is installed?

The ideal use case would be that a user decides to install an application and, as part of the postinstall script, the application icons are added to the desktop. After that, when the application is uninstalled, they icons are automatically removed from the desktop.

  • 2
    just a note: its generally bad form for a package to be messing with the /home/ dir in any way - this includes adding shortcuts to the desktops of users (as there is no central "Global Desktop" folder like that in Windows). – Thomas Ward Jul 12 '11 at 15:29

As already mentioned, this isn't something that should be done for an official package. Though I could see how this might be useful in a local deployment.

Use something like this in debian/postinst:

for user in /home/*
    cp /usr/share/applications/foo.desktop ${user}/Desktop/
    chmod 755 ${user}//Desktop/foo.desktop
  • -1 for chmod 777 – enzotib Jul 12 '11 at 19:19
  • @enzotib Why -1 in chmod? I've tried to manually add an icon to my desktop and I see that the file is executable. However, the file isn't exactly the same as the original, the following is prepended: #!/usr/bin/env xdg-open So probably using sed to add that line and chmod to make it executable would work. Do you agree? – jcollado Jul 13 '11 at 6:15
  • Using and suggesting to use 777 permissions is always wrong: another user of the same machine could modify the Exec= line of your .desktop file. You never find files with 777 permissions in files installed by packages, it is a bad habit. Change your mode to 755 and I remove my downvote. – enzotib Jul 13 '11 at 7:20

From design of Unity the desktop is not the place of first choice where applications icons are meant to be (of course you can easily put them there if your workflow needs this).

Having said so, it is therefore reasonable that newly installed applications are put on the launcher rather than on the desktop. By installing from the Software Center you need to press More Info rater than Install

enter image description here

to find a button Add to Launcher on the lower right:

enter image description here

Select this option to put the application's icon on the launcher after a successful installation:

enter image description here

  • I didn't know about the "Add to launcher" button. Thanks for the information. – jcollado Jul 13 '11 at 6:17
  • You only see it when installing over the More Info button (or when installing downloaded DEB packages btw)- that's why it is not so well known. – Takkat Jul 13 '11 at 6:20

As a previous poster had suggested, it's bad form to touch things in /home/USER during installation. As mentioned there isn't a Global Desktop that you can add it to, so what happens if there are multiple users on the system? Or a user is added after installation?

That said, I believe you could do it in postinst by copying the .desktop file to the /home//Desktop/ folder. You would also want to have a prerm (or perhaps postrm) to remove the file during uninstallation. Verify the file is there before removing in case the user deleted the desktop icon (Also, what happens if a different user uninstalls it?). At this point, this is getting pretty messy.

Technically speaking, that should work. I'm just not sure if you would be able to get that past REVU to be included in the official Ubuntu repositories.

  • Thanks for your response. I just wanted it for a personal package, so no problem if the package doesn't completely follow the official policies. – jcollado Jul 13 '11 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.