Xfce Forum

Sub domains
 

You are not logged in.

#1 2018-03-18 17:42:29

albertine
Member
Registered: 2018-03-18
Posts: 3

Writing a .desktop file that exec a Bash script (solved)

Hi everyone,

Here is a simple thing which won't work, and that even after a lot of googling and testing...
In fact I'm trying to populate the Thunar>SendTo menu with some commands, I know (and already did) it's possible to do that with UCA, but here specifically I want it this way, with .desktop files...

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)

Offline

#2 2018-03-18 18:44:20

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: Writing a .desktop file that exec a Bash script (solved)

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)


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 2018-03-18 19:51:26

albertine
Member
Registered: 2018-03-18
Posts: 3

Re: Writing a .desktop file that exec a Bash script (solved)

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 :
1521402294.png

And when you success, do you receive all of the parameters in the script ?

You also have %k in your desktop file

Well, so Thunar does not implements the .desktop specifications? Perhaps only partially?

Offline

#4 2018-03-18 21:39:51

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: Writing a .desktop file that exec a Bash script (solved)

What version of thunar are you working with?

And when you success, do you receive all of the parameters in the script ?

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.

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 2018-03-18 21:44:35

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: Writing a .desktop file that exec a Bash script (solved)

albertine wrote:

Well, so Thunar does not implements the .desktop specifications? Perhaps only partially?

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


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

#6 2018-03-18 21:49:20

albertine
Member
Registered: 2018-03-18
Posts: 3

Re: Writing a .desktop file that exec a Bash script (solved)

What version of thunar are you working with?

V 1.6.12

Well, it seems this is the "Terminal=true" and the " --hold" of xfce4-terminal options that are causing that mess...
When I remove them:

[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!

So it looks like the following are returning something:
- f
- F
- i
- c

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)

Offline

Board footer

Powered by FluxBB