Xfce Forum

Sub domains
 

You are not logged in.

#1 2020-05-03 10:47:00

oliver_stotz
Member
Registered: 2020-05-02
Posts: 7

.desktop - dnd usage with filenames that contain spaces

Hi, this is my first message here, so i hope i get everything right ...

First off, I love XFCE and would like to stick to it. So I also want to understand it a little better to tweak it.

This is my goal:
Use .desktop file to allow for drag'n'drop actions for various tasks. For the sake of simplicity i pick a very simple task to show where i'm having problems with. The task is just to copy a file from my home folder to my "~/Templates" folder when it is dropped upon "test.desktop".
In the tests, one file is called "testfile", the other is called "this file contains spaces"

1.) accomplish the task using an external script called "copytest.sh":

#!/bin/bash
rm ~/Templates/*
cp -v "$1" ~/Templates

in the .desktop file (called "test.desktop") this is my Exec entry:
Exec=/home/oliver/copytest.sh %F

the copy process for both filenames works ok, as long as I have "Terminal=false". When i use "Terminal=true" (for debugging reasons), the parsing of the filename containing spaces fails. Putting quotes around %F (single or double) doesn't change anything.

2.) accomplish the task using a one-liner in "Exec", invoking a new terminal window to open:

in the .desktop file (called "test.desktop") this is my Exec entry:
Exec=gnome-terminal -e "bash -c 'cp -v "%F" ~/Templates;$SHELL'"

Here, the file with spaces in its name always fails, and is broken up after each space, no matter what i do with the %F variable.

Can anyone here shed further light on this ?

Two more questions in this regard (hopefully not off-topic):

a.) When "Terminal=true", can i leave the terminal window open to see possible error messages ?
b.) can i define an environment variable in the Exec line ? if yes, how ?
(i didn't succeed in doing so. here is what i tried:
Exec=env MYVAR="%F" && gnome-terminal -e "bash -c 'echo hello $MYVAR;$SHELL'"

Thanks for any hints !

Offline

#2 2020-05-03 12:40:57

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,056

Re: .desktop - dnd usage with filenames that contain spaces

Hello and welcome.

Which distro and which version of Xfce are you using?

Using your example above, #1 works for me regardless of the value of Terminal= (Arch Linux - latest dev version of Xfce)

With #2, the important thing to note is that the "~" does not get properly processed. I'm not sure if this is an Xfce issue or a larger freedesktop implementation issue. You should use the full path. With respect to holding the window open, xfce4-terminal has an -H option to do so - not sure if gnome-terminal has a similar option. So redoing the Exec= line, I used:

Exec=xfce4-terminal -H -e "cp -v %F /home/toz/Templates"

...and it worked for both filenames with and without spaces. Plus, it displays and holds the terminal window open so you can see the output.

Other questions:
a) I'm not sure you can. Since you are already running gnome-terminal, look to see if it has an option to hold the terminal window open after execution. xfce4-terminal has the "-H" option for this purpose.
b) it should look something like... Exec=env MYVAR=value command

I'm going to test this on an official 4.14 release to see if there is some potential Xfce bug at play here.

Edit: Tested on Xubuntu 20.04 with similar results.

Last edited by ToZ (2020-05-03 12:47:40)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2020-05-03 14:30:05

oliver_stotz
Member
Registered: 2020-05-02
Posts: 7

Re: .desktop - dnd usage with filenames that contain spaces

Hi, thanks a lot for that reply !

As for my system: Debian 4.19.98-1 (2020-01-26) x86_64 GNU/Linux, XFCE 4.12

My default terminal is "qterminal" actually, but i never succeeded in calling it from a .desktop file, hence the gnome-terminal.

I can confirm that your suggestion: "Exec=xfce4-terminal -H -e "cp -v %F /home/toz/Templates"" works alright for both files AND keeps the terminal window open as you said. So i will maybe stick to that since the -H switch doesn't seem to work on the gnome-terminal.

But now another strange issue occured:

I tried to expand the task by a second command (empty Templates folder first, then copy file %F into it). This is what i wrote:

Exec=xfce4-terminal -H -e "rm /home/oliver/Templates/* ;cp -v %F /home/oliver/Templates"

this command gave me this output:

rm: cannot remove '/home/oliver/Templates/*': No such file or directory
rm: cannot remove ';cp': No such file or directory
removed '/home/oliver/this file contains spaces.2'
rm: cannot remove '/home/oliver/Templates': Is a directory

So i reckon the command is understood as "remove all elements seperated by a white space (after the rm command)",
rather than "FIRST execute the rm command, THEN execute the cp command" as it would normally do in a terminal.
seems like the ";" is interpreted literally rather than a chaining operator, right ?

how would i tell the xfce4-terminal to do this ?
(sorry if this is too obvious - i'm just a beginner at scripting ...)

Best

Offline

#4 2020-05-03 19:41:58

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,056

Re: .desktop - dnd usage with filenames that contain spaces

oliver_stotz wrote:

seems like the ";" is interpreted literally rather than a chaining operator, right ?

Correct. The interpreter that is used is not a full shell so it can't process special characters.

However, you can encapsulate everything inside of a shell (eg. bash) to complete the task. It would look like this:

Exec=xfce4-terminal -H -e "bash -c 'rm /home/oliver/Templates/* ;cp -v %F /home/oliver/Templates"'

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2020-05-03 20:31:03

oliver_stotz
Member
Registered: 2020-05-02
Posts: 7

Re: .desktop - dnd usage with filenames that contain spaces

We're getting close ;-)

Your suggestion gave me a "Launch Error" (Text ended before matching quote was found for ' ...),
so i guess the right syntax would be:

Exec=xfce4-terminal -H -e "bash -c 'rm /home/oliver/Templates/* ;cp -v %F /home/oliver/Templates'"

which i tried and which runs without error.

HOWEVER: this way %F is not correctly parsed, as it is truncated after the first white space:
("cp: missing destination file operand after '/home/oliver/eee'"), so it seems that if %F contains a space it cannot be fully passed along to the bash process from the .desktop interpreter with your proposed method.

My workaround for the moment is this:

Exec=xfce4-terminal -H -e "/home/oliver/copytest.sh %F"

which gives me both a debugging terminal AND the correct name parsing to the shell script.
Still, I hoped to get along without having to use an extra shell script.

Anyway, thanks a lot for all your efforts, much appreciated !

Offline

#6 2020-05-04 00:09:32

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,056

Re: .desktop - dnd usage with filenames that contain spaces

Yeah, I can't get it to parse spaces either. Using a script is a good workaround - you don't have to worry about the simplified shell environment.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

Board footer

Powered by FluxBB