You shall know the truth,
& the truth shall set you free. —John 8:32

Biju Ale


Computing Tools

Personal reference of scripts, commands, and automation tools.


LaTeX

Letter template

LaTeXletter.tex

Wrap text around a figure

LaTeXwrapfigure.tex

Word count with texcount

  1. Generate: texcount.pl -1 -sum document.tex -out=document.sum
  2. In preamble: \newcommand\wordcount{\input{\jobname.sum}} then call \wordcount where needed
  3. Detailed summary: \usepackage{verbatim} then \newcommand\wordcount{\verbatiminput{\jobname.sum}}
  4. Multi-file: add -inc flag to texcount.pl

PDF

Scanned PDF → B&W (Otsu threshold)

Pythonpdf_bw_otsu.py

Scanned PDF → B&W (simple threshold)

Run ocrmypdf on the output afterwards to restore the text layer.

Pythonpdf_bw_simple.py

Resize all PDFs to A4

Bashpdf_resize_a4.sh

Trim first page from all PDFs

Bashpdf_trim_first.sh

Batch DjVu → PDF

Bashdjvu_to_pdf.sh

Convert JPGs to PDF (per file)

for i in *.jpeg; do convert "$i" -auto-orient "${i%.jpeg}.pdf"; done

Combine all images into one PDF

convert *.jpg -auto-orient pictures.pdf

Search text inside PDFs

pdfgrep -C 3 -HiR -e "search term" *.pdf

Extract images from a PDF

mkdir extracted-images && pdfimages -all <path-to-pdf> extracted-images/image

llpp clipboard config (Linux)

Config~/.config/llpp.conf

Image

Auto-rotate EXIF orientation, then stamp a copyright notice on every image. Output files are prefixed f_.

Bashcopyright_watermark.sh

Remove white background (trim)

magick img1.jpeg -trim +repage img1_trim.jpeg

Vertical stitch (top → bottom)

magick img1.jpeg img2.jpeg -append final.jpeg

Horizontal stitch (side by side)

magick img1.jpeg img2.jpeg +append final.jpeg

Audio

MKV → MP3 (recursive)

find . -name '*.mkv' -exec bash -c 'ffmpeg -i "$1" -vn -b:a 320000 -y "${1%.mkv}.mp3"' _ {} \;

FLAC → M4A (Apple Lossless)

Usage: ./flac_to_m4a.sh flac m4a ./src ./dest

Bashflac_to_m4a.sh

FLAC → Video (static cover art)

Muxes audio with a still image into MP4. Usage: ./flac_to_vid.sh flac mp4 ./src ./dest

Bashflac_to_vid.sh

Split single FLAC with cue sheet

  1. Install tools: sudo pacman -Syu cuetools shntool
  2. Navigate to the directory with the .flac and .cue files
  3. Split: shntool split -f *.cue -o flac *.flac
  4. Tag: cuetag.sh *.cue split-track*.flac

Files

Folder binning by keyword

Moves all files whose name contains a given string into a subfolder of that name.

Pythonfolder_bin.py

rsync — basic recursive

rsync -r <source>/ <destination>/
rsync -a <source>/ <destination>/

rsync — verbose dry-run (preview changes)

rsync -av --dry-run <source>/ <destination>/

rsync — mirror (deletes destination-only files)

rsync -av --delete --dry-run <source>/ <destination>/

rsync — backup to remote (compressed)

rsync -zaP <source> user@ip_address:<destination>/

Recursive find and copy by extension

find ./ -name '*.xsl' -exec cp -prv '{}' '/path/to/targetDir/' ';'

Recursive copy matching files (multiple dirs)

find '/source-path' -name '*.JPG' -exec cp -t '/destination-path' {} +

Delete all files of an extension (Windows)

for /R %f in (*.flac) do echo del "%f" | cmd

Web

Internet Archive — get collection item list

ia search 'collection:mir_titles' --itemlist > items.txt

Internet Archive — download all PDFs (10 parallel)

Bashia_download.sh

Selenium starter

Pythonselenium_starter.py

wget — recursive PDF download

Bashwget_recursive.sh

wget — fix filenames from Content-Disposition

wget -c -i urls.txt --restrict-file-names=windows --content-disposition

wget — download archived MIT courseware

Bashwget_mit_ocw.sh

Mac

Remove stubborn login items

Delete the relevant entries for the offending app from these directories:

Pathslogin-item-dirs

Automator — add files to Calibre

Create a Quick Action in Automator (accepts files in Finder), add a Run Shell Script step:

Bashadd_to_calibre.sh