Thunar custom actions

Post your tutorials and howtos here.
User avatar
ilu
Posts: 2060
Joined: 09 Oct 2013 12:45

Thunar custom actions

Postby ilu » 15 Mar 2018 06:02

I don't like Thunar as a file manager since I prefer having two panes but custom actions are really useful. SolydX already comes with these: Open Terminal, Open Folder as root, Open file as root, Create symlink, GTK Hash, Mount/Unmount ISO, Burn ISO, Print File, Search, Install .ttf font, Rotate clockwise and Rotate counter-clockwise. I have some more and I'm always looking for suggestions. Sadly you can't just copy this code into your ~/.config/Thunar/uca.xml since it has unique-id tags (which I removed). You'll have to create the custom action (with the id) by giving it a name via the GUI. Now close all Thunar windows! You can then edit ~/.config/Thunar/uca.xml and copy-paste the rest. If you want to enter the commands posted here into the GUI you need to convert " to " and ' to '.

1. This one is really a must-have if you work with media files, Dependencies: mediainfo, zenity. The same functionality would be possible with ffmpeg/avconv but more complicated.

Code: Select all

<action>
	<icon>mediainfo</icon>
	<name>Media File Metadata</name>
	<command>mediainfo %N | zenity --text-info --title="Media Info" --width=600 --height=2000</command>
	<description>Grabs info from a media (audio/video) file using ffmpeg</description>
	<patterns>*</patterns>
	<audio-files/>
	<image-files/>
	<other-files/>
	<video-files/>
</action>
2. This helps to save storage space if you are not interested in the video part of a music video. Dependency: ffmpeg, but avconv should also work.

Code: Select all

<action>
	<icon>audio-card-symbolic</icon>
	<name>Extract M4A Audio</name>
	<command>bash -c &apos;ffmpeg -i "$0" -map 0:1 -c:a copy "${0%%.*}".m4a&apos; %F</command>
	<description>Extract as m4a</description>
	<patterns>*.flv;*.mp4</patterns>
	<video-files/>
</action>
3. Samba stuff - I'm not sure where I got these from and I don't use them :?

Code: Select all

<action>
	<icon>folder-remote</icon>
	<name>Samba public read-only</name>
	<command>net usershare add %n %f "" Everyone:R guest_ok=y</command>
	<description>Create a public read only samba share</description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>folder-remote</icon>
	<name>Samba public writeable</name>
	<command>net usershare add %n %f "" Everyone:F guest_ok=y && chmod 777 %f</command>
	<description>Create a public writeable samba share</description>
	<patterns>*</patterns>
	<directories/>
</action>
<action>
	<icon>folder-remote</icon>
	<name>Samba remove share</name>
	<command>net usershare delete %n && chmod 755 %f</command>
	<description>Remove a samba share</description>
	<patterns>*</patterns>
	<directories/>
</action>
4. Stripping PDF meta data before publishing them is a must but difficult. This will purge the regular metadata but be aware that some applications might hide more metadata in the file (f.e. in embedded images). Dependencies: exiftool, qpdf.

Code: Select all

<action>
	<icon>application-pdf</icon>
	<name>Show PDF metadata</name>
	<command>pdftk %N dump_data  | zenity --text-info --title="PDF Toolkit" --width=600 --height=2000</command>
	<description>Show PDF metadata</description>
	<patterns>*.pdf</patterns>
	<other-files/>
</action>
<action>
	<icon>xpdf</icon>
	<name>Strip PDF</name>
	<command>exiftool -all:all=  -overwrite_original %f && qpdf --linearize %f stripped.pdf</command>
	<description>Permanently strip PDF metadata</description>
	<patterns>*.pdf</patterns>
	<other-files/>
</action>
It would be nice to replace "out.pdf" with some combination of the original filename and a number but I haven't figured out how.

I'd like to insert a new title and author tag with these ones, but sadly the input from zenity into the tag doesn't work. I'd need to get the zenity input into a variable and fill the tag from there ... can anybody help?

Code: Select all

<action>
	<icon>xpdf</icon>
	<name>PDF Title Tag</name>
	<command>exiftool -Title=" " %N | zenity --entry --title="Change title tag" --text="New title:" --entry-text=" "</command>
	<description>Enter a new title tag in PDF metadata</description>
	<patterns>*.pdf</patterns>
	<other-files/>
</action>
<action>
	<icon></icon>
	<name>PDF author</name>
	<command>exiftool -Author=" " %N | zenity --entry --title="Change author tag" --text="New author:" --entry-text=" "</command>
	<description>Edit PDF author tag</description>
	<patterns>*.pdf</patterns>
	<other-files/>
</action>
5. No idea if anybody else finds these two useful, I needed them:

Code: Select all

<action>
	<icon>arrow-right-double</icon>
	<name>ImgMergeHor</name>
	<command>convert +append %F joined-horizontal.png</command>
	<description>Glue images horizontally</description>
	<patterns>*</patterns>
	<image-files/>
</action>
<action>
	<icon>arrow-down-double</icon>
	<name>ImgMergeVer</name>
	<command>convert -append %F joined-vertical.png</command>
	<description>Glue images vertically</description>
	<patterns>*</patterns>
	<image-files/>
</action>
Does anybody have more suggestions for custom actions?

kurotsugi
Posts: 2116
Joined: 09 Jan 2014 00:17

Re: Thunar custom actions

Postby kurotsugi » 15 Mar 2018 08:56

interesting. I already use ffmpeg for converting the video stuff into mp3 for quite a long time. though, I tend to use higher bitrate to avoid missing stuffs on the compression stage.

User avatar
ilu
Posts: 2060
Joined: 09 Oct 2013 12:45

Re: Thunar custom actions

Postby ilu » 15 Mar 2018 17:31

Bitrate won't help you much with bits that are not there to begin with ... I use m4a because I want to keep original AAC encoding from the mp4 video. It's supposed to be just cutting out the audio without change. No re-encoding into mp3 means best possible quality. I haven't tested much but it seems to work. Feedback on quality welcome.

kurotsugi
Posts: 2116
Joined: 09 Jan 2014 00:17

Re: Thunar custom actions

Postby kurotsugi » 15 Mar 2018 22:47

I'm afraid not. AFAIK the process involves re-encoding regardless the output. the audio bits are streamed out then decoded into desired format. using m4a means that we will use aac compression instead of mp3. using aac indeed has some merits but in my experience the default setting simply doesn't cut for several kind of music. my personal reference for mp3 are : 128 is for speech and old music, 192 is for most modern music, 225 is for complex music, 320 is overkill.

if you doesn't want to do re-encoding, the solution would be downloading the audio straight from the source. for an example, youtube actually separated their audio and video stuff. you can use youtube-dl to only download the audio streaming. "youtube-dl -F" should gives you all the available formats.

User avatar
Tuna130
Posts: 48
Joined: 10 Aug 2013 05:40
Location: Spain

Re: Thunar custom actions

Postby Tuna130 » 18 Oct 2018 12:24

I wrote a bash script that scrubs meta data from PDF files, and I use it as a custom action from Thunar. Being a bash script, off course it can be run from terminal or through other file managers. This is my first bash script from scratch, so I am sure there is plenty to improve on; just let us know.

Add new custom action from menu in Thunar:
name: PDF Scrub
description: remove pdf meta data
command: /home/me/.config/Thunar/custom/pdfscrub.sh %N
files: ‘other’ *.pdf;*.PDF

I made a folder /home/me/.config/Thunar/custom but park script file anywhere you like.
A log file is created called pdfscrub.log were scrubings are collected, in the folder of the pdf file.

Code: Select all

#! /usr/bin/env bash
# PDF Scrub by Tuna130, 15th Oct 2018
# This script is intended as a custom action for Thunar file manager for "other files" *.pdf;*.PDF, with command /path/to/pdfscrub.sh %N

#loop to handle all selected files
for selectedfile; do

#workaround for file names with spaces
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# show meta data in zenity and ask, surpressing Gtk errors
pdfinfo $selectedfile | zenity --text-info --title=$selectedfile --width=400 --height=500 --cancel-label="Scrub..!" 2> >(grep -v 'Gtk' >&2) || scrub=1
# when not "ok" doublepipe sets scrub to 1
if [[ "$scrub" -ne 0 ]] ; then

    date +"%D %R" >> pdfscrub.log # start log for coprology
    echo $selectedfile >> pdfscrub.log # add filename
    pdfinfo $selectedfile >> pdfscrub.log # add summary of data that will be deleted
    echo -en '\n' >> pdfscrub.log # nice empty line

    pdftk $selectedfile dump_data output pdfdump
    sed -re 's/(InfoValue: )[^=]*$/\1  /' pdfdump > cleaninfo # replace all after "InfoValue: " with space. Tweak here.
    rm pdfdump
    pdftk $selectedfile update_info cleaninfo output clean.pdf
    rm cleaninfo
    mv --update --force clean.pdf $selectedfile
    scrub=0
fi
IFS=$SAVEIFS

done

User avatar
ilu
Posts: 2060
Joined: 09 Oct 2013 12:45

Re: Thunar custom actions

Postby ilu » 18 Oct 2018 13:44

Uh, nice! I'm going to test this next time I need to clean a PDF.


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest