Score:0

KDE Menu Editor writes inverted commas that shouldn't be in the command

br flag

I have noticed this a few times while trying to add new application launchers/icons to the launcher's menu list in Kubuntu or when editing the existing ones.

In some cases the inverted commas appear only in the KDE Menu Editor after I have manually edited the corresponding .desktop file and made sure that the Exec= command is ok. In this case there is no problem with the execution of the command and the launcher works.

For example, I have the file ~/.local/share/applications/software-properties-qt.desktop with the line Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true software-properties-qt, which works just fine. But the KDE Menu Editor or the Application Launcher right-click menu option "Edit Application" show this:

env 'DISPLAY=$DISPLAY' 'XAUTHORITY=$XAUTHORITY' KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true software-properties-qt

enter image description here

But in some cases when I am trying to use the KDE Menu Editor to create new launchers, without using any inverted commas, these are nonetheless created in the .desktop file with bad results, and I have to modify the .desktop file manually and remove the inverted commas.

For example, opening the KDE Menu Editor and creating a new entry/launcher for playing inserted DVD in VLC with the simple command vlc dvd://,

enter image description here

it doesn't work because in the file ~/.local/share/applications/VLC DVD.desktop this line was created, which doesn't look right: Exec='vlc dvd://'. That doesn't work.


Here's another example:

Apper software manager cannot be used properly if launched simply as apper (the default command in its installed launcher /usr/share/applications/org.kde.apper.desktop), because it cannot get the needed rights and gives an error at the end:

enter image description here

I have found that what works is to use this command:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper

which requires the password at the start and then works as expected.

For that command, I have created a new file ~/.local/share/applications/org.kde.apper.desktop.

When I open the file in Kate text editor, the Exec= line is followed by the command as seen above. But when I use the KDE Menu editor or the "Edit application" context menu option in the application launcher widget, — I see this command: pkexec env 'DISPLAY=$DISPLAY' 'XAUTHORITY=$XAUTHORITY' KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper.

enter image description here

enter image description here


enter image description here

enter image description here

"Why are those inverted commas there" would count as a question by itself, to be asked from pure curiosity (given that the application works fine, as things are) were it not for the fact that if I try to create a new entry in the KDE Menu Editor, in this case in order to launch Apper in update mode (apper --updates), by simply copying the command for Apper proper and just adding --updates argument, the result is not working, although the only difference between the two entries in the KDE Menu Editor is that argument.

Well, testing that line (as seen in the menu editor) in a terminal, it doesn't work:

pkexec env 'DISPLAY=$DISPLAY' 'XAUTHORITY=$XAUTHORITY' KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper
qt.qpa.xcb: could not connect to display $DISPLAY
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

Aborted (core dumped)

Why does the application Apper work then, while the new entry "Update with Apper" doesn't when launched from the application launcher (kickoff, krunner) ? Because their real Exec= lines in the corresponding .desktop files in ~/.local/share/applications are different: only the one newly created through the KDE Menu Editor (for updates in Apper) —unlike the old one (for just launching Apper)— contains the inverted commas, although in the menu editor both have them!

I have to manually edit the file ~/.local/share/applications/Update with Apper.desktop and remove the inverted commas for it to work, that is change this:

Exec=pkexec env 'DISPLAY=$DISPLAY' 'XAUTHORITY=$XAUTHORITY' KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper --updates

into this:

Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper --updates

The commas are fine as long as they appear in the menu editor but not in the .desktop file itself.

But why do they appear there? How does this all work?

muru avatar
us flag
Two things: 1. Since this thing has separate fields for program and command line arguments, for the `vlc` example, `vlc` should go in the program field and everything else in the command line arguments field, and 2. Since there is no shell involved in running the command line in the `Exec` field, you'd have to use something like `sh -c 'pkexec ...'` to get the environment variables to expand correctly, so here the command would be `sh` and the arguments would be `-c 'pkexec ...`. Or just put the command in a script and execute that.
br flag
@muru - I've just realized the VLC part myself and posted an answer. But I think about asking a different question about why those inverted commas in the menu editor but not in the file. The Apper example remains obscure: a format that doesn't seem ok in the menu editor is not corrected there after correction of the file, but still works. shouldn't the menu editor reflect changes in the file? - About the shell: I trust what you say but how come I have to add `sh -c` into the menu editor if I don't need that in the `.desktop` file?
muru avatar
us flag
Because it just happens to work for you, but [the spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables) (AIUI) doesn't specify that it should. Using `sh -c 'pkexec env "DISPLAY=$DISPLAY" "XAUTHORITY=$XAUTHORITY" KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true software-properties-qt'` is how I'd expect it to work for any implementation, not just the one you're using. Also, the spec shows why the quoting is added - it does say that reserved characters like `$` should be quoted.
br flag
@muru - The oddest thing is that a change in the file is not reflected in the menu editor. As long as I know the working command I can put that in the file. But I don't trust the menu editor for such long commands. The VLC case clarifies for me the general situation though.
muru avatar
us flag
I'd expect the command to be `sh` + `-c 'pkexec env "DISPLAY=$DISPLAY" "XAUTHORITY=$XAUTHORITY" KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper --updates'`, but anyway, yes, putting complex commands in a script is just the simplest way here.
Score:0
br flag

I don't know why this is exactly (I will ask a new question on that), but the decisive thing here is that the KDE Menu Editor has separate entries for the program and for its arguments, and the command has to be separated there for it to be written correctly in the .desktop file.

This can be verified by editing the VLC-DVD launcher with the correct line Exec='vlc dvd://', which gives in the menu editor:

enter image description here

It seems that in the KDE Menu Editor the program and the arguments must be inserted on the separate lines.

The problem is more complicated with the other example for Apper. The problem there is not with the inverted commas, it seems to me (why are they present in the menu editor and not the file will be the topic of the new question), but with the fact that the command for updates with Apper involves not just multiple programs but also multiple arguments. Thus, just for launching Apper proper with the needed environment and the administrative rights, it worked fine with pkexec on the "Program" line and with env 'DISPLAY=$DISPLAY' 'XAUTHORITY=$XAUTHORITY' KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true apper on the "Command-Line Arguments" line (apper working here as CLI argument too). But it doesn't work by just adding --updates to that line in the menu editor, maybe because that is a new argument (inside the already present argument!), and thus triggers the error of putting the bad inverted commas in the file itself. This case remains obscure to me, because after correcting the file (removing the inverted commas), the KDE Menu Editor shows the same entries as the ones that didn't work before! (I hope that would be clarified in the new question. It may be that the menu editor cannot follow and work above a certain level of complexity of the command.)

Anyway, the answer to this question —why the bad inverted commas in the launcher file— is because of improper edits in the menu editor: the line of command should be split between the fields "Program" and "CLI arguments", the simplest solution being to put sh in the program field and -c 'THE REST OF IT ALL' in the arguments field, or simply put the command in a script and just add the path to the script in the program field.

— based on comments by @muru:

Using sh -c 'pkexec env "DISPLAY=$DISPLAY" "XAUTHORITY=$XAUTHORITY" KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true software-properties-qt' is how I'd expect it to work for any implementation

Since there is no shell involved in running the command line in the Exec field, you'd have to use something like sh -c 'pkexec ...' to get the environment variables to expand correctly, so here the command would be sh and the arguments would be -c 'pkexec .... Or just put the command in a script and execute that

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.