KDE desktop field codes

This is a compilation of desktop field codes I use in KDE. There are more field codes, but they are deprecated and shouldn’t be used. This compilation was found on the Freedesktop homepage, and the following quote is their description of field codes:

A number of special field codes have been defined which will be expanded by the file manager or program launcher when encountered in the command line. Field codes consist of the percentage character (“%”) followed by an alpha character. Literal percentage characters must be escaped as %%. Deprecated field codes should be removed from the command line and ignored. Field codes are expanded only once, the string that is used to replace the field code should not be checked for field codes itself.
%f A single file name, even if multiple files are selected. The system reading the desktop entry should recognize that the program in question cannot handle multiple file arguments, and it should should probably spawn and execute multiple copies of a program for each selected file if the program is not able to handle additional file arguments. If files are not on the local file system (i.e. are on HTTP or FTP locations), the files will be copied to the local file system and %f will be expanded to point at the temporary file. Used for programs that do not understand the URL syntax.
%F A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program.
%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.
%i The Icon key of the desktop entry expanded as two arguments, first –icon and then the value of the Icon key. Should not expand to any arguments if the Icon key is empty or missing.
%c The translated name of the application as listed in the appropriate Name key in the desktop entry.
%k The location of the desktop file as either a URI (if for example gotten from the vfolder system) or a local filename or empty if no location is known.


These field codes can be used to send information to your desktop programs upon execution. For instance, you can have your own script to run from the service menus in dolphin. Just create a textfile in ~/.kde/share/kde4/services/ServiceMenus/ and give it a .desktop extension.

[eek@narcissus [23:13:20] servicemenus]$ cat 20-convertText.desktop
[Desktop Entry]

[Desktop Action 2unix]
# convert and preserve date/time
Exec=/usr/bin/dos2unix -k -o %F
Name=To UNIX format

[Desktop Action 2dos]
# convert and preserve date/time
Exec=/usr/bin/unix2dos -k -o %F
Name=To DOS format

To see the environmental variables currently known to your desktop environment, as well as the field codes above, create a script with this content:

[eek@narcissus [23:13:24] servicemenus]$ cat 999-writeKdeEnvironment.desktop
[Desktop Entry]

[Desktop Action WriteEnv]
Exec=env >/tmp/kde-env.log ; echo "%%U: %U" >>/tmp/kde-env.log ; echo "%%u: %u" >>/tmp/kde-env.log ; echo "%%F: %F" >>/tmp/kde-env.log ; echo "%%f: %f" >>/tmp/kde-env.log ; echo "%%i: %i" >>/tmp/kde-env.log ; echo "%%c: %c" >>/tmp/kde-env.log ; echo "%%k: %k" >>/tmp/kde-env.log ; gvim -f /tmp/kde-env.log ; rm /tmp/kde-env.log
Name=Write KDE Environment (debug)

Select some files from the service menus:

Service menus

Select some files from the service menus

Depending on what was selected, you can see the results of the field codes in the temporary file that is created and opened in gvim:

Values of field codes

Values of field codes


Ok, that was a brief overview, originally just intended as a reminder for myself…


This entry was posted in Linux and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *