Thunar custom actions

Post your tutorials and howtos here.
User avatar
ilu
Posts: 2677
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: 2267
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: 2677
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: 2267
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: 60
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.

Depends on: pdftk, zenity

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
# dependency: pdftk, zenity
# 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: 2677
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.

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

Re: Thunar custom actions

Postby Tuna130 » 02 Apr 2020 10:35

Last night I put this one together, a custom action for merging pdf files into one file.
It works on file names with spaces, and can save to a file name with spaces.

Code: Select all

#! /usr/bin/env bash
# pdf_merge for merging pdf docs in Thunar by Tuna130
# Dependencies: ghostscript/pdftk, zenity
# Place this script in ~/.config/Thunar/custom, and make executable with chmod +x, then add custom action ~/.config/Thunar/custom/pdf_merge.sh %N, applicable to *.pdf files 

## copy files to tempdir and rename files with spaces
mkdir tempdir
cp "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10" tempdir # up to 10 files, add more if needed
cd tempdir
find . -depth -name '* *' | while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done

## convert with ghostscript for better results
gs -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dCompatibilityLevel=1.4 -dQUIET -o -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=output.pdf *.pdf

## convert with pdftk for slightly smaller file
# pdftk *.pdf cat output output.pdf

## zenity
filename=$(zenity --entry --entry-text="Type" --text="Save as: " --title="PDF Merge")

## for use in terminal
# echo "File Name: " 
# read filename

## file handling
cd ..
mv tempdir/output.pdf "$filename".pdf
rm -rf tempdir

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

Re: Thunar custom actions

Postby ilu » 02 Apr 2020 11:06

Nice, thank you!

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

Re: Thunar custom actions

Postby Tuna130 » 03 Apr 2020 20:10

Make an animated GIF file from your images with this script.
GIFmaker builds a portable slideshow that will play from any device.

Code: Select all

#! /usr/bin/env bash
# gifmaker script is for making a portable gif slideshow from Thunar file manager, by Tuna130
# dependencies: imagemagick zenity
# Place this script in ~/.config/Thunar/custom, and make executable with chmod +x.
# Add custom action ~/.config/Thunar/custom/gifmaker.sh %N, applicable to image files 

mkdir -p GIF # destination subfolder for gif file

ms=$(zenity --entry --text="Enter delay between images (ms) ..." --entry-text=80 2> >(grep -v 'Gtk-' >&2)) # set delay and supress gtk error

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

#loop for resize
for file; do 
    resized="GIF/""${file%%.*}"  
    convert -interlace Plane -gaussian-blur 0.05 -quality 85% -resize 720x1100 "${file}" "${resized}".jpg # tweak resize options here
done

#Zenity progress bar dialog and pipe into convert
(
echo "10" ; sleep 0.2
echo "# Resizing" ; sleep 0.2
echo "20" ; sleep 0.2
echo "# Resizing" ; sleep 0.5
echo "50" ; sleep 0.2
echo "# Building GIF" ; sleep 0.5
echo "75" ; sleep 0.2
echo "# Ready: "$resized.gif ; sleep 0.5
echo "100" ; sleep 0.2
) |
zenity --progress --title "GIF maker" \
  --text "Converting image to animation..." --percentage=0 \
  $(convert -delay "$ms" -loop 0 "GIF/"*.jpg "$resized".gif) 2> >(grep -v 'Gtk-' >&2)
# gif file gets file name of last image

rm "GIF/"*.jpg

IFS=$SAVEIFS

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

Re: Thunar custom actions

Postby Tuna130 » 11 Apr 2020 15:28

Shrink pdf files.
Have you ever had an online form refuse your pdf attachment because it was to large? Here is the solution with pdf_mini.sh, a very simple script that makes an easy custom action for Thunar.

Code: Select all

#! /usr/bin/env bash
# pdf_mini.sh for shrinking pdf docs in Thunar by Tuna130
# Dependencies: ghostscript 
# Place this script in ~/.config/Thunar/custom, and make executable with chmod +x, then add custom action ~/.config/Thunar/custom/pdf_mini.sh %N, applicable to *.pdf files 

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

#loop for all files
for file; do 

#shrink (PDFSETTINGS choose screen: 72 dpi, ebook: 150 dpi, printer: 300 dpi)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${file%.*}_.pdf $file #result has "_" to name

# end loops
done
IFS=$SAVEIFS


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests