[SOLVED] XFCE - Scripting and GUI integration via Thunar Custom action

Technical issues/questions of an intermediate or advanced nature.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[SOLVED] XFCE - Scripting and GUI integration via Thunar Custom action

Post#1 by Rava » 25 Nov 2021, 22:22

All major info for your reading convenience:
ncmprhnsbl's 3 suggestions in post #2
donald's suggestion in post #3
My choice for now with 4 screenshots illustrating how it's done in post #4 (Screenshots starting with "And for the convenience of our forum visitors: 4 screenshots showing how easily that is set up (shot 1 & 2) and what it looks like in practice (shot 3 & 4)" part of that post)
____________________

I created a small script that should give me some info on a media file:

Code: Select all

#!/bin/sh
VERSION="0.1"
MYNAME="ffprobe-hide_banner"

echo -e "$MYNAME V$VERSION"

ffprobe -hide_banner "$*"
read
The issue: it is meant to be started in the GUI, or else I would not need the read command at the end. And it should be an option to be executed when opening the context menu, aka "Open with other application" when clicking on a multimedia file, e.g. a mp3, mp3, whatever music or video file.

But in XFCE, there is no window opening. All happens in an invisible background process.
And in XFCE, I see no option to start that command e.g. in uxterm.

Can that be set so it is possible to start certain commands (like the above) in uxterm? And how do I set that up in XFCE (V4.12)

If that is not possible, then I need to put the info from ffprobe into one of the script based window-creators (whatever you call these) like the info window activate or deactivate opens when started in the GUI.

Which would also be okay since it forces me to create something new, script-wise, and that is excellent mental training. :happy62:
Cheers!
Yours Rava

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

XFCE - Scripting and GUI integration question

Post#2 by ncmprhnsbl » 26 Nov 2021, 00:43

various ways to do this..
  • uxterm -e <your_script.sh> or even a script that calls that or create a "thunar custom action" (menubar>Edit>Configure Custom Actions) with that command and mimetype "Appearance Conditions"
  • create a .desktop file(goes in /usr/share/applications or ~.local/share/applications) that 1. executes your script 2. has the mimetypes required 3. has line: Terminal=true (this, after a database update should appear in the 'open with' list)
  • as you say "script based window-creators" ..in v5* : /usr/share/porteus/gtkdialog.py eg. in place of your echo: /usr/share/porteus/gtkdialog.py -p "$MYNAME V$VERSION" -t 2000 & (-t 2000 = disappears after 2 secs)
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

donald
Full of knowledge
Full of knowledge
Posts: 2064
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

XFCE - Scripting and GUI integration question

Post#3 by donald » 26 Nov 2021, 02:31

...some info on a media file....when opening the context menu..
A thunar custom action will do.

Code: Select all

xfce4-terminal --hold -e "ffprobe -hide_banner %f"

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - Scripting and GUI integration question

Post#4 by Rava » 26 Nov 2021, 09:33

Thanks ncmprhnsbl and donald!
ncmprhnsbl wrote:
26 Nov 2021, 00:43
various ways to do this..
I look into each one, every approach has its advantages and disadvantages… Maybe I code all three and then decide after testing all which one to choose.
donald wrote:
26 Nov 2021, 02:31
A thunar custom action will do.

Code: Select all

xfce4-terminal --hold -e "ffprobe -hide_banner %f"
consulting man xfce4-terminal

Code: Select all

   -H, --hold

   Causes the terminal to be kept around after the child command has
   terminated
[…]
   -e, --command=command

   Execute command inside the terminal
I see, good solution as well.
I presume the saved settings for xfce4-terminal - especially the larger than standard font size (DejaVu Sans Mono Book 16) since I run my 5.0rc3 on a FullHD monitor - will also be used by that command, especially since all other manually started xfce4-terminal do also use my adapted settings.

Now I have 4 ways doing it.
It is still 3 ways doing it since #1 from ncmprhnsbl is the same as the suggestion by donald (difference: using uxterm or using xfce4-terminal )

I choose donald's solution for now since I did not manage to set up uxterm running with a larger font size. I recall from its man page that it has some global settings in /etc/ or such.

And for the convenience of our forum visitors: 4 screenshots showing how easily that is set up (shot 1 & 2) and what it looks like in practice (shot 3 & 4)

Image

Image

Image

Image

Looks good. :celebrate3:

The xfce4-terminal opened and was empty for a second or such waiting for ffprobe to collect its info.
Since the custom action not uses my script and calls ffprobe directly (as seen that my script from the first post above does only that as well) my script is not needed; using a script instead (e.g. because it does more than just executing a single command [e.g. like my make-ffplay-script does - see Rava's Coding Goodies for details]) then you also need to have that script readable and executable in guest's $PATH for the Thunar custom action to work.
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - Scripting and GUI integration question

Post#5 by Rava » 26 Nov 2021, 10:22

One issue remains.
Since I do not use "save changes" I need to save such changed settings manually.
I went into guest's ~/.config/xfce4 folder and executed a find / xarg / grep command for finding only the recent changed files: (or be more precise only the files changed today)

Code: Select all

guest@porteus:~/.config/xfce4$ find . -mtime 0 2>/dev/null | xargs ls -oad --color=auto --time-style=long-iso 2>&1 |grep -vE "cache| .$| ..$"|grep "2021-11-26"
-rw-r--r--  1 guest  105 2021-11-26 10:49 ./xfce4-screenshooter
drwxr-xr-x  2 guest  320 2021-11-26 11:18 ./xfconf/xfce-perchannel-xml
-rw-r--r--  1 guest 1523 2021-11-26 11:18 ./xfconf/xfce-perchannel-xml/thunar.xml
Seems the Thunar Custom Action is not saved in ~/.config/xfce4 ?
Because it is not to be found in the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/thunar.xml

Added in 5 minutes 9 seconds:
[SOLVED] XFCE - Scripting and GUI integration via Thunar Custom action
Update
and solved the issue. Unlike what one might presume, some Thunar settings are not saved in the xfce4/ folder but in ~/.config/Thunar/uca.xml :

Code: Select all

guest@porteus:~/.config$ find . -mtime 0 2>/dev/null | xargs ls -oad --color=auto --time-style=long-iso 2>&1 |grep -vE "cache| .$| ..$"|grep "2021-11-26 10:45"
drwxr-xr-x  2 guest     100 2021-11-26 10:45 ./Thunar
-rw-------  1 guest    7881 2021-11-26 10:45 ./Thunar/uca.xml
And in ~/.config/Thunar/uca.xml is this new entry now at the very end:

Code: Select all

<action>
	<icon>totem</icon>
	<name>Multimedia File Info</name>
	<unique-id>1637919937787832-1</unique-id>
	<command>xfce4-terminal --hold -e &quot;ffprobe -hide_banner %f&quot;</command>
	<description></description>
	<patterns>*</patterns>
	<audio-files/>
	<video-files/>
</action>
:D
Cheers!
Yours Rava

Post Reply