Automating Tasks with Nautilus Scripts

Posted Sunday 29 May 2022 by Urs Riggenbach.

Nautilus scripts are a versatile way to automate daily tasks such as reducing PDF sizes, converting pictures to PDFs, adding notes to documents, etc.

The below files help creating PDFs, with varying degrees of compression.
"Normal" is a compression to 300dpi, which will still allow the PDF to be printed and is the best choice in most cases. When a higher compression level is needed, the "Smaller" and "Smallest" scripts can be useful.

First run:
mkdir .local/share/nautilus/scripts/

Then create the 3 files:

nano .local/share/nautilus/scripts/PDF\ Resize\ Normal

#!/bin/bash
echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | xargs -i gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile="{}"_min.pdf "{}"

nano .local/share/nautilus/scripts/PDF\ Resize\ Smaller

#!/bin/bash
echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | xargs -i gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="{}"_min.pdf "{}"
nano .local/share/nautilus/scripts/PDF\ Resize\ Smallest
#!/bin/bash
echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | xargs -i gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile="{}"_min.pdf "{}"

Lastly, make the files executable.

chmod +x .local/share/nautilus/scripts/*

Now, the three scripts shouldbe available to you from the context menu on any file in your nautuilus file browser in GNOME.