Command line command to refresh GUI desktop, like when pressing F5?

16,368

Solution 1

If refreshing is tricky, we can restart Nautilus:

pkill nautilus
nautilus -n

Your Startup Applications entry can be easily modified to add these commands as well, as part of script, by chaining:

udisks --mount  ... && pkill -u nautilus && nautilus -n

Nautilus has a -q option to make it quit by itself, but this doesn't work well with nautilus -n.

Solution 2

You could emulate pressing the key with xdotool, if you can not find how to directly call the function it is mapped to:

xdotool key F5

The difficult part is to do that when the current window is not the desktop.
It should be possible to find it with th search command - but may need some experimenting;

First, try to find the right window, using getwindowname to show the title of matched windows:

xdotool search --class Desktop getwindowname

If the result looks right, try:

xdotool search --class Desktop key F5

Otherwise, see man xdotool for many more options of xdotool search.
If you need more information about the existing windows to make it work, these commands are the most useful for inspecting them: xwininfo and xprop.

Solution 3

There is one stupid, but simple solution (and it works). You can cd to Desktop and then create and remove some temporary folder in terminal. That will trigger refresh action on Desktop.

mkdir some_folder_name && rm -rf some_folder_name

Share:
16,368
Eduardo De Mello Castanho
Author by

Eduardo De Mello Castanho

Updated on September 18, 2022

Comments

  • Eduardo De Mello Castanho
    Eduardo De Mello Castanho over 1 year

    Is there any command to refresh the desktop icons (exactly like F5 button does)?

    I need this because in Startup Applications I set a command to mount my backup partition and I've created a desktop link to some directories there. The problem is that the icons are not refreshed when I log in, unless I press F5. I would like to put a command in the Startup Applications to do so. (note that I don't want to restart the GNOME shell or Unity, like they said here. I just need a command to do exactly what F5 does)

  • muru
    muru over 9 years
    You could use xdotool to type in the shortcut for minimize all windows (Super-D ?) and then use it type in F5.
  • Eduardo De Mello Castanho
    Eduardo De Mello Castanho over 9 years
    Volker Siegel, the getwindowname didnt worked. It simply executes and shows no message (same when trying the third command, with Desktop key). I tried xwininfo and xprop and they didnt give me any useful information for this case. Still, I tried xdotool key F5. On the command line, obviously was just like pressing F5 on the command line and not on the Desktop; on the Startup Apps, it did nothing, probably because he`s still not on the Desktop window by the time he executes the command. The solution that worked with me was the one 'muru' gave on the comments: restarting Nautilus Thanks anyway
  • Volker Siegel
    Volker Siegel over 9 years
    @muru I agree, restarting nautilus is much better for your case. I leave this answer here because it is useful for others with similar cases when it's not possible to restart. And yes, it's difficult to find the right search pattern for the window;