Desktop file Exec arguments
albertine Member Registered: 2018-03-18 Posts: 3 Show
Hi everyone, Here is a simple thing which won't work, and that even after a lot of googling and testing... The Bash script (/home/myuser/test.sh): #!/bin/bash echo "Argument(s) $# : $@." The .desktop file (/home/myuser/.local/share/Thunar/sendto/test.desktop): # Try n1 [Desktop Entry] Type=Application Version=1.0 Encoding=UTF-8 Terminal=true Exec=/home/myuser/test.sh param1 %k %F Icon=my-icon Name=Test SendTo # Try n2 [Desktop Entry] Type=Application Version=1.0 Encoding=UTF-8 Terminal=true Exec=/usr/bin/bash -c /home/myuser/test.sh param1 %k %F Icon=my-icon Name=Test SendTo # Try n3 [Desktop Entry] Type=Application Version=1.0 Encoding=UTF-8 Terminal=false Exec=xfce4-terminal --hold --execute /usr/bin/bash -c /home/myuser/test.sh param1 %k %F Icon=my-icon Name=Test SendTo As you can see, I tried with three different .desktop file version. Every try is failing, sometimes Xfce displays an error "...Xterm process execution failed..." or sometimes terminal starts, the script runs but without receiving and displaying parameters/arguments (param1 %k %F)... So what's wrong? Is anybody here getting what the **** is going on? This sounds like something stupid... Thanks! Last edited by albertine (2018-03-20 13:55:49)
ToZ Moderator From: Canada Registered: 2011-06-02 Posts: 8,603
Hello and welcome. Using your test.sh script and the first desktop file works here. The one thing that I did notice that might be tripping you up, is that Thunar seems to cache the desktop file. You have to quit thunar ("thunar -q") and re-start it to force it to re-read the desktop file (if you make any changes). I also changed your test.sh file to read: #!/bin/bash echo "Argument(s) $# : $@." > /tmp/test.log ...so I could tail the test.log file to see exactly what it prints out when it recieves the info from thunar. You also have %k in your desktop file, it doesn't return anything. Only the %F works. Last edited by ToZ (2018-03-18 18:44:49)
albertine Member Registered: 2018-03-18 Posts: 3
Hi ToZ, I've just tried with your setup and Xfce complain about xterm missing error when I (here) SendTo my ~/Images (or whatever else) folder : And when you success, do you receive all of the parameters in the script ?
Well, so Thunar does not implements the .desktop specifications? Perhaps only partially?
ToZ Moderator From: Canada Registered: 2011-06-02 Posts: 8,603
What version of thunar are you working with?
This is my .desktop file: [Desktop Entry] Type=Application Version=1.0 Encoding=UTF-8 Terminal=true Exec=/tmp/test.sh param1 %F p2 Icon=my-icon Name=Test SendTo And this is what gets entered into /tmp/test.log when I select 2 files and send to "Test SendTo": Argument(s) 4 : param1 /home/toz/Downloads/1_webp_a.webp /home/toz/Downloads/20180119.pdf p2.
ToZ Moderator From: Canada Registered: 2011-06-02 Posts: 8,603
Here is what the following Exec line: Exec=/tmp/test.sh f %f F %F u %u U %U i %i c %c k %k ...returns: Argument(s) 12 : f /home/toz/Downloads/1_webp_a.webp F /home/toz/Downloads/20180119.pdf u U i --icon my-icon c Test SendTo k. So it looks like the following are returning something:- f- F- i - c
albertine Member Registered: 2018-03-18 Posts: 3
V 1.6.12 Well, it seems this is the "Terminal=true" and the " --hold" of xfce4-terminal options that are causing that mess... [Desktop Entry] Type=Application Version=1.0 Terminal=false Exec=xfce4-terminal --execute /home/myuser/test.sh param1 %F Icon=my-icon Name=Test SendTo Then use this script with sleep() to let me see the output: #!/bin/bash echo "Argument(s) $# : $@ ..." #> /tmp/test2.log sleep 10 Everything is working as expected!
Perfect man, thank you very much!! Edit : Much better is to replace "sleep 10" with "read", this whay terminal result is displayed as long its open. Last edited by albertine (2018-03-18 22:03:35) Recognized desktop entry keysKeys with type localestring may be postfixed by [LOCALE], where LOCALE is the locale type of the entry. LOCALE must be of the form lang[_COUNTRY][ ENCODING][ MODIFIER], where _COUNTRY, .ENCODING, and @MODIFIER may be omitted. If a postfixed key occurs, the same key must be also present without the postfix. When reading in the desktop entry file, the value of the key is selected by matching the current POSIX locale for the LC_MESSAGES category against the locale postfixes of all occurrences of the key, with the .ENCODING part stripped. The .ENCODING field is used only when the Encoding key for the desktop entry file is Legacy-Mixed, (see Appendix�D, The Legacy-Mixed encoding (Deprecated).) The matching of is done as follows. If LC_MESSAGES is of the form LANG_COUNTRY.ENCODING@MODIFIER, then it will match a key of the form LANG_COUNTRY@MODIFIER. If such a key does not exist, it will attempt to match LANG_COUNTRY followed by LANG@MODIFIER. Then, a match against LANG by itself will be attempted. Finally, if no matching key is found the required key without a locale specified is used. The encoding from the LC_MESSAGES value is ignored when matching. If LC_MESSAGES does not have a MODIFIER field, then no key with a modifier will be matched. Similarly, if LC_MESSAGES does not have a COUNTRY field, then no key with a country specified will be matched. If LC_MESSAGES just has a LANG field, then it will do a straight match to a key with a similar value. The following table lists possible matches of various LC_MESSAGES in the order in which they are matched. Note that the ENCODING field isn't shown. For example, if the current value of the LC_MESSAGES category is sr_YU Latn and the desktop file includes: Name=Foo Name[sr_YU]=... Name[sr Latn]= Name[sr]=...then the value of the Name keyed by "sr_YU" is used. Case is significant. The keys "Name" and "NAME" are not equivalent. The same holds for group names. Key values are case sensitive as well. Keys are either OPTIONAL or REQUIRED. If a key is optional it may or may not be present in the file. However, if it isn't, the implementation of the standard should not blow up, it must provide some sane defaults. Additionally, keys either MUST or MAY be supported by a particular implementation. Some keys only make sense in the context when another particular key is also present. Some example keys: Name[C], Comment[it]. Table�2.�Standard Keys
Character set encoding of the fileDesktop entry files are encoded as lines of 8-bit characters separated by LF characters.
Comment lines are uninterpreted and may contain any character (except for LF). However, using UTF-8 for comment lines that contain characters not in ASCII is encouraged. The encoding for values of type localestring is determined by the Encoding field. List of valid Exec parameter variablesEach "Exec" field may take a number of arguments which will be expanded by the file manager or program launcher and passed to the program if necessary. Literal % characters must be escaped as %%, and adding new format characters is not allowed. It's a fatal error to have an Exec field with a format character not given in the spec (exception to this are the deprecated format characters which can be ignored, that is expanded to no parameters, by the implementation). Again for emphasis: nonstandard extensions are not allowed here - you must add an X-Foo-Exec field if you have nonstandard Exec lines. The escaping of the exec parameters is done in the way the mailcap specification describes. Take a look at RFC 1524 for more information. Recognized fields are as follows: Detailed discussion of supporting MIME typesIt is in every desktop's best interest to have thorough support for mime types. The old /etc/mailcap and /etc/mime.types files are rather limited in scope and frankly, are outdated. Various desktop systems have come up with different ways of extending this original system, but none are compatible with each other. The Desktop Entry Standard hopes to be able to provide the beginnings of a solution to this problem. At a very basic level, the "Exec" key provides the default action to take when the program described by a desktop entry is used to open a document or data file. Usually this consists of some action along the lines of "kedit %f" or "ee %f". This is a good start, but it isn't as flexible as it can be. Let us first establish that a program which supports a MIME type or multiple mime types may be able to support multiple actions on those MIME types as well. The desktop entry may want to define additional actions in addition to the default. The toplevel "Exec" key describes the default action; Let us define this action to also be known as the "Open" action. Additional actions which might be possible include View, Edit, Play, etc. A further revision of this document will probably specify several "standard" actions in addition to the default "Open" action, but in all cases, the number of actions is arbitrary. Let us use a sound player as a simple example. Call it sp. The default Exec (Open) action for this program would likely look something like: Exec=sp %uHowever, imagine the sound player also supports editing of sound files in a graphical manner. We might wish to define an additional action which could accomodate this. Adding the action would be performed like this: Actions=Edit; [Desktop Action Edit] Exec=sp -edit %uAs you can see, defining the action "edit" will enable an additional group of the name [Desktop Action actionname] to be read. This group can contain an additional Exec line, as well as possibly other information like a new Name, Comment, Icon, and Path. Thus right-clicking on a .wav file will show both the default "Open" action and this "Edit" action to both be displayed as choices in the context-menu. A left click (double or single, whichever the file manager implements) would cause the default action to take place. These are implementation-specific details which are up to the implementer, and are not enforced by this standard. If no DefaultApp is specified for a particular MIME type, any one of the programs registered which claim to be able to handle the MIME type may become the default handler. This behaviour is undefined and implementation-specific. KDE doesn't use a DefaultApp anymore, but assigns a Preference number to each program, so that the highest number is the one chosen for handling the MIME type. If the standard is to be amended with a new {key,value} pair which should be applicable to all supporting parties, a group discussion will take place. This is the preferred method for introducing changes. If one particular party wishes to add a field for personal use, they should prefix the key with the string "X-PRODUCT", i.e. "X-NewDesktop-Foo", following the precedent set by other IETF and RFC standards. Alternatively, fields can be placed in their own group, where they may then have arbitrary key names. If this is the case, the group should follow the scheme outlined above, i.e. [X-PRODUCT GROUPNAME] or something similar. These steps will avoid namespace clashes between different yet similar environments. A.�Example Desktop Entry File[Desktop Entry] Version=1.0 Type=Application Encoding=UTF-8 Name=Foo Viewer Comment=The best viewer for Foo objects available! TryExec=fooview Exec=fooview %F Icon=fooview.png MimeType=image/x-foo X-KDE-Library=libfooview X-KDE-FactoryName=fooviewfactory X-KDE-ServiceType=FooService [Desktop Action Inverse] Exec=fooview --inverse %f Name=Foo Viewer (inverse image) [Desktop Action Edit] Exec=fooview --edit %f Name=Foo Viewer (edit image) Icon=fooview-edit.pngB.�Currently reserved for use within KDEDuring the time KDE added some extensions that are currently not prefixed by the "X-" prefix, but should be in future KDE releases.
As this standard is quite old there are some deprecated items that may or may not be used by serveral implementations.
D.�The Legacy-Mixed encoding (Deprecated)The Legacy-Mixed encoding corresponds to the traditional encoding of desktop files in older versions of the GNOME and KDE desktop files. In this encoding, the encoding of each localestring key is determined by the locale tag for that key, if any. For keys without a locale tag, the value must contain only ASCII characters. If the file specifies an unsupported encoding, the implementation should either ignore the file, or, if the user has requested a direct operation on the file (such as opening it for editing), display an appropriate error indication to the user. In the absence of an Encoding line, the implementation may choose to autodetect the encoding of the file by using such factors as:
If the implementation does not perform such auto-detection, it should treat a file without an Encoding key in the same way as a file with an unsupported Encoding Key. If the locale tag includes an .ENCODING part, then that determines the encoding for the line. Otherwise, the encoding is determined by the language, or language-country pair from the locale tag, according to the following table. Encoding The name given here is listed here is typically the canonical name for the encoding in the GNU C Library's iconv facility Encodings marked with (*) are not currently supported by the GNU C Library; for this reason, implementations may choose to ignore lines in desktop files that resolve to this encoding. Desktop files with these encodings are currently rare or non-existent. AliasesOther names for the encoding found in existing desktop files. TagsLanguage tags for which this is the default encoding. This table above covers all tags and encodings that are known to be currently in use. Implementors may choose to support encodings not in the above set. For tags without defaults listed in the above table, desktop file creators must specify the ENCODING part of the locale tag. Matching the ENCODING part of the locale tag against a locale name or alias should be done by stripping all punctuation characters from both the tag and the name or alias, converting both name and alias to lowercase, and comparing the result. This is necessary because, for example, "Big5" is frequently found instead of "BIG5" and "georgianacademy" instead of GEORGIAN-ACADEMY. Desktop files creators should, however, use the name as it appears in the "Encoding" column above. |