Cinnamon Nemo File Browser Custom Actions
I often make png images (mainly for this site) and one helpful tool to compress them is pngcrush.
I'm quite comfortable on the command line, but I thought there must be an easy way to do what I want just by right clicking.
Nemo (the file browser for the Cinnamon desktop environment) supports this easily.
Simply create a new action file. My example is called "pngcrush.nemo_action" and is created in user specific .local folder - mine being /home/dan/.local/share/nemo/actions.
You can click on More Info to show some documentation.
The content of this file is:
[Nemo Action] Active=true Name=Compress PNG Comment=Compress PNG Dependencies=pngcrush Selection=notnone Quote=double Exec=<pngcrush.sh %F> Icon-Name=gtk-execute Extensions=png;
Key configurations here:
- Dependencies=pngcrush - means it won't show unless pngcrush is installed (done through Software Manager, or sudo apt install pngcrush)
- Selection=notnone - means the action won't show up when right clicking, but it will show if one or more files are selected
- Quote=double - escapes file names with spaces.
- Extensions=png; - this means the action will only show on png files. If at least one selection is not a png file, the action won't show.
- Icon-Name=gtk-execute - just gives a gear icon
- Exec=<pngcrush.sh %F> - finally, this says what script to run. The %F parameter means "insert path list of selection"
The script itself is a bash script that loops through the list of files sent and executes the command. The file named pngcrush.sh should also be created in the same folder ~/.local/share/nemo/actions. It also needs to be made executable (change via right click properties, or run a terminal in the actions directory and type chmod +x pngcrush.sh):
Here is the content of the sh file:
#!/bin/bash for i in "$@"; do if [ -x "$i" ]; then continue fi pngcrush -brute "$i" "${i%%.*}_crushed.png" done
The loop expands the input parameter to each file, into an i variable. To get the filename without the extension, greedy parameter expansion is used (the ${i%%.*} bit)
In the examples of this blog, this brought the screenshots from 104.4KB to 75.1KB - saving approximately 25% bandwidth. This helps more on larger articles/blogs and images.