104

When editing the Applications menu, I see for some applications their commands have %U such as gedit %U and gnome-mplayer %U, but others don't such as gcalctool.

I was wondering what %U means when calling a command, and when it is needed and when it is not? Thanks!

This is motivated from my previous question, where I followed a reply but did not make it work.

wjandrea
  • 14,543
Tim
  • 26,197

2 Answers2

108

It's a parameter for the Exec key in .desktop files (defined in the Desktop Entry Specification) that describes how arguments to the program (from the file manager/program launcher, e.g. multiple selected files) should be handled:

%u A single URL. Local files may either be passed as file: URLs or as file path.

%U A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path.

So, e.g., /usr/share/applications/gedit.desktop contains:

Exec=gedit %U

which means that arguments to gedit will be treated as a list of URLs (or local files).

For a complete list of possible parameters, see The Exec key.

Salim B
  • 135
htorque
  • 66,134
  • 2
    Thanks! (1) Could you give some examples? (2) When will none of these is specified? – Tim Mar 13 '11 at 19:31
  • 53
    The reason these parameter keys exist is so the desktop manager knows what to do if you open multiple selected objects at the same time or drop one or more objects on it. %U means the program can take all of them in a single invocation; %u means a separate invocation is needed for each object; if none of them are specified then the program doesn't know what to do with things dropped on it. There are other keys which allow the desktop manager to pass customization information to the program, and a separate set of selectors %f, %F, meaning it takes one/multiple files but not URLs. – geekosaur Mar 13 '11 at 20:22
  • Is there a way to pass a parameter to have the programme start minimised on startup? – Andor Kiss Mar 18 '20 at 11:32
  • I think the URL for "The Exec key" should be https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html and not https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html. – Elijah Lynn May 14 '20 at 21:45
  • 1
    Great answer, was so perplexed by this in a *.desktop entry and this answer nailed it! – Elijah Lynn May 14 '20 at 21:45
  • The link to the Desktop Entry Specifications is precious! Thanks, +1 — I wonder why the link is not given in the help documentation :( – loved.by.Jesus Aug 13 '21 at 10:42
2

Thanks for a really useful answer, still helpful 13 years on.

The %U may also be found within a Flatpak command line, as for example:

/usr/bin/flatpak run --command=calibre --file-forwarding com.calibre_ebook.calibre --detach @@u %U @@

The --file-forwarding option takes URIs within the @@u %U @@ phrase and passes these to the called program as individual URIs on the command line.

RAG
  • 21