81

Let's say I changed/added some myapp.desktop file at ~/.local/share/applications/. For some time Ubuntu Unity will still show me old applications shortcuts at Unity lens under Ubuntu button. It will take some time (or just a one restart) to get applications list updated there.

How I can force Unity reload ~/.local/share/applications and reflect shortcuts correctly in lens?

Radu Rădeanu
  • 169,590
vladimir
  • 1,517
  • 2
  • 13
  • 9
  • Have you tried unity --reset? – sayantankhan Nov 12 '13 at 15:36
  • Correction. It should just be unity. Press alt+F2 and type in the command. – sayantankhan Nov 12 '13 at 15:41
  • Yes. It didn't help. It still shows old application name after unity or unity --reset (which was before I modified myapp.desktop file). – vladimir Nov 12 '13 at 16:55
  • Odd, it seems to be working fine when I do the exact same thing you're doing. Have made sure the .desktop file is executable? – sayantankhan Nov 12 '13 at 17:26
  • It works only after log off/restart. Try just to change the name of existing application inside the desktop file. Don't change anything else. For ex, add " Test" to the name of some existing app. Now press Ubuntu button and start typing application name - it still shows old name without " Test" for me. I reproduced it on both work and home machines and on wife's laptop. I think it's about 100% reproducable. – vladimir Nov 12 '13 at 18:26
  • Confirmed. It is reproducible. – sayantankhan Nov 12 '13 at 19:01
  • 1
    Analogous question for newer Ubuntus: https://unix.stackexchange.com/questions/12118/how-do-i-refresh-gnome-3-applications. – wrwrwr Aug 02 '20 at 16:34

7 Answers7

91

A little late, but i stumbled upon this thread before finding a solution, atleast to my problem, googling something related, nearly giving up.

As per this guide help.ubuntu.com, don't just edit or create your .desktop files in /usr/local/share/applications or ~/.local/share/applications. Instead, create the file somewhere else and use

desktop-file-install <your_file.desktop>

to add the file.

E.g. you create ~/myapp.desktop and do

desktop-file-install --dir=$HOME/.local/share/applications ~/myapp.desktop

Existing files of the same name will be overwritten and unity updated, you can use --delete-original if the source is not needed anymore, or

sudo desktop-file-install ~/myapp.desktop

to install it for all users.

a3nm
  • 423
Rodin
  • 1,026
  • 8
  • 3
  • +1 this works. A rough edit script using this recipe is at https://gist.github.com/hilbix/f468fcbb15c3f68670d8 – Tino May 25 '14 at 09:51
  • 5
    just putting a copy of the .desktop file in ~/.local/share/applications worked for me- – chrismarx Mar 18 '15 at 14:01
  • I usually manually edit the file and add it to .local/share/applications/. Tried using the command with --delete-original and I got a warning: warning: key "Keywords[uk]" is a list and does not have a semicolon as trailing character, fixing. The result was the source file deleted and nothing copied to the target directory. Evil OS... basically nuked my file and I had to create a new one from scratch. – Daniel Mar 09 '17 at 11:00
  • 4
    I still get the issue OP noticed even when doing this. – JAB Mar 28 '17 at 16:22
  • 2
    I also still get the issue OP noticed even when doing this (and even after restarting) (Ubuntu 16.04). – Dan Nissenbaum Jul 22 '17 at 18:05
  • This also works with plasma ( kde ). But, what does desktop-file-install do other than copying the file contents into /usr/share/applications ( in case of sudo ) ? – infoclogged Aug 04 '17 at 09:23
  • I put the original desktop files under a local version control in subversion and use this method to deploy them. This makes it easier to deploy on new OS installs. On caveat I noticed is that the desktop may not refresh the first time you hit the Super key but does the second time. – Timothy C. Quinn Dec 17 '20 at 20:45
  • This solutions only works for me, if I go to dir=$HOME/.local/share/application then right click to the corresponding application.desktop and allow the permission of the execution. – Name Jun 27 '21 at 15:17
25

sudo update-desktop-database will refresh the .desktop database.

18

The way to do this is to run the command

killall unity-scope-home

after opening the dash the process is started automatically again.

The correct icons are then displayed...

wa4557
  • 900
8

According with this answer (and you can find many others in the same sense), unfortunately there seems to be no command to let the unity-applications-daemon refresh its application cache. But I can confirm that unity will automatically detect any changes with .desktop files in ~/.local/share/applications. If these changes are not immediately available, try logging out and in again to refresh it.

Radu Rădeanu
  • 169,590
  • 3
    Yeah, it will automatically detect .... in an hour ... – vladimir Nov 12 '13 at 18:28
  • @vladimir As I said, if you want the changes immediately available, try logging out and in again to refresh it. – Radu Rădeanu Nov 12 '13 at 18:29
  • 3
    I fully got your answer and probably will accept it. You understand downsides of logging off - all opened apps closed. It's not a solution, it's a workaround and not a user friendly one. Are you developer by any chance? If yes, could you please point me to the daemon sources? I guess this is it: unity-lens-applications daemon.vala – vladimir Nov 12 '13 at 21:28
5

This answer does not involve a desktop restart.


Though quite late, there's a utility command to update the desktop database cache named update-desktop-database.

Updating stuffs added in $HOME/.local/share/applications/, use:

>> update-desktop-database

Updating stuffs addded in global ones, like /usr/share/ubuntu/applications, /usr/share/gnome/applications, /usr/share/applications, etc., use:

>> sudo update-desktop-database
Adam
  • 151
  • 1
  • 4
0

Some applications might stop working properly after this command. Chrome, for example, became totally black.

unity --replace
0

I had a similar issue, fixed when restart. I use ubuntu 16.04

I usually create .desktop files in /usr/share/applications/ if I want to share the desktop files with other users and ~/.local/share/applications if for only one user. And I usually restart.