[READ-ONLY] Mirror of https://github.com/mrgnw/scripts.
1#!/bin/zsh
2
3# Bulk process all PDFs in a folder in parallel
4# Usage: pdf-compress-img-bulk [num_parallel_jobs]
5
6folder="${1:-.}" # Default to current directory
7num_jobs="${2:-0}" # Default to 0 (use all available cores)
8
9if [[ ! -d "$folder" ]]; then
10 echo "Error: Directory '$folder' does not exist"
11 exit 1
12fi
13
14# Count PDFs
15pdf_count=$(find "$folder" -maxdepth 1 -type f -name "*.pdf" | wc -l)
16if [[ $pdf_count -eq 0 ]]; then
17 echo "No PDFs found in '$folder'"
18 exit 0
19fi
20
21echo "Found $pdf_count PDF(s). Starting parallel compression..."
22
23# Process each PDF in parallel using gnu parallel
24find "$folder" -maxdepth 1 -type f -name "*.pdf" | parallel -j "$num_jobs" pdf-compress-img
25
26echo "Bulk compression complete!"