Skip to content

Instantly share code, notes, and snippets.

@szeyu
Last active June 21, 2026 03:53
Show Gist options
  • Select an option

  • Save szeyu/698a37d134f0797c5e2d3c08e8c4a49c to your computer and use it in GitHub Desktop.

Select an option

Save szeyu/698a37d134f0797c5e2d3c08e8c4a49c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Nautilus script to compress selected PDFs by approximate size ratio
# Requires: ghostscript, zenity, notify-send
if [ "$#" -eq 0 ]; then
zenity --error --text="No PDF selected."
exit 1
fi
# Ask user for compression multiplier
RATIO=$(zenity --scale \
--title="Compress PDF" \
--text="Choose target size multiplier.\n\nExample:\n30 = try around 30% of original size\n50 = try around 50% of original size\n80 = light compression" \
--min-value=10 \
--max-value=90 \
--value=50 \
--step=10)
if [ -z "$RATIO" ]; then
exit 0
fi
# Convert ratio to Ghostscript settings
# Lower ratio = stronger compression
if [ "$RATIO" -le 20 ]; then
RESOLUTION=72
JPEG_QUALITY=35
elif [ "$RATIO" -le 40 ]; then
RESOLUTION=96
JPEG_QUALITY=45
elif [ "$RATIO" -le 60 ]; then
RESOLUTION=120
JPEG_QUALITY=55
elif [ "$RATIO" -le 80 ]; then
RESOLUTION=150
JPEG_QUALITY=70
else
RESOLUTION=200
JPEG_QUALITY=80
fi
for input in "$@"; do
LOWER_FILE="${input,,}"
if [[ "$LOWER_FILE" != *.pdf ]]; then
notify-send "Invalid File" "'$input' is not a PDF."
continue
fi
DIR="$(dirname "$input")"
BASENAME="$(basename "$input" .pdf)"
output="$DIR/${BASENAME}_compressed_${RATIO}x.pdf"
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-dDetectDuplicateImages=true \
-dCompressFonts=true \
-dSubsetFonts=true \
-dAutoRotatePages=/None \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution="$RESOLUTION" \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution="$RESOLUTION" \
-dMonoImageDownsampleType=/Subsample \
-dMonoImageResolution="$RESOLUTION" \
-dJPEGQ="$JPEG_QUALITY" \
-sOutputFile="$output" \
"$input"
if [ $? -eq 0 ]; then
ORIGINAL_SIZE=$(du -h "$input" | cut -f1)
NEW_SIZE=$(du -h "$output" | cut -f1)
notify-send "PDF Compressed" "Original: $ORIGINAL_SIZE → New: $NEW_SIZE"
else
notify-send "PDF Compression Failed" "Failed to compress '$input'."
fi
done
#!/bin/bash
for FILE in "$@"; do
# Convert filename to lowercase
LOWER_FILE="${FILE,,}"
# Check if the file has a supported extension
if [[ "$LOWER_FILE" == *.pptx || "$LOWER_FILE" == *.docx || "$LOWER_FILE" == *.doc ]]; then
# Get the directory and filename without extension
DIR="$(dirname "$FILE")"
BASENAME="$(basename "$FILE")"
# Convert to PDF using LibreOffice
libreoffice --headless --convert-to pdf --outdir "$DIR" "$FILE"
# Optional: Notify the user of completion
notify-send "Conversion Complete" "Converted '$BASENAME' to PDF."
else
notify-send "Invalid File" "'$FILE' is not a supported document (.pptx/.docx/.doc)."
fi
done
#!/bin/bash
# Get full path of selected file
input="$1"
# Check if input ends with .webm
if [[ "$input" != *.webm ]]; then
zenity --error --text="This script only works on .webm files."
exit 1
fi
# Generate output file name
output="${input%.webm}.mp4"
# Launch in terminal to show progress
gnome-terminal -- bash -c "
echo 'Converting \"$input\" to \"$output\"...';
ffmpeg -i \"$input\" -vcodec libx264 -crf 23 \"$output\";
echo '';
echo 'Done!';
read -p 'Press Enter to close...' var
"
#!/bin/bash
# Nautilus script to merge selected PDFs with pdfunite
# Get directory of the first selected file
dir="$(dirname "$1")"
output="$dir/Merged.pdf"
# Run pdfunite on all selected files
pdfunite "$@" "$output"
# Notify user
if [ $? -eq 0 ]; then
notify-send "PDF Merge" "Merged into $output"
else
notify-send "PDF Merge Failed" "Something went wrong."
fi

Nautilus Script for Linux

A collection of Nautilus Script for you to copy and paste

#!/bin/bash
# Nautilus script to convert PDF into image-only PDF
# Output is saved as a separate file.
# Requires: poppler-utils, img2pdf, zenity, notify-send
if [ "$#" -eq 0 ]; then
zenity --error --text="No PDF selected."
exit 1
fi
DPI=$(zenity --scale \
--title="PDF to Image PDF" \
--text="Choose image quality DPI.\n\n150 = smaller file\n200 = balanced\n300 = sharper but larger file" \
--min-value=100 \
--max-value=300 \
--value=200 \
--step=50)
if [ -z "$DPI" ]; then
exit 0
fi
for input in "$@"; do
LOWER_FILE="${input,,}"
if [[ "$LOWER_FILE" != *.pdf ]]; then
notify-send "Invalid File" "'$input' is not a PDF."
continue
fi
DIR="$(dirname "$input")"
BASENAME="$(basename "$input" .pdf)"
output="$DIR/${BASENAME}_image_only.pdf"
# Avoid overwrite
counter=1
while [ -e "$output" ]; do
output="$DIR/${BASENAME}_image_only_${counter}.pdf"
counter=$((counter + 1))
done
TEMP_DIR="$(mktemp -d)"
pdftoppm \
-jpeg \
-r "$DPI" \
"$input" \
"$TEMP_DIR/page"
if [ $? -ne 0 ]; then
notify-send "Conversion Failed" "Failed to convert '$input' to images."
rm -rf "$TEMP_DIR"
continue
fi
img2pdf "$TEMP_DIR"/*.jpg -o "$output"
if [ $? -eq 0 ]; then
ORIGINAL_SIZE=$(du -h "$input" | cut -f1)
NEW_SIZE=$(du -h "$output" | cut -f1)
notify-send "PDF Converted" "Created:
$output
Original: $ORIGINAL_SIZE
New: $NEW_SIZE"
else
notify-send "PDF Conversion Failed" "Failed to create image-only PDF."
fi
rm -rf "$TEMP_DIR"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment