Skip to content

Instantly share code, notes, and snippets.

@mbforbes
Created October 11, 2018 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbforbes/83d3efab3d8be7926325c044a9aa8329 to your computer and use it in GitHub Desktop.
Save mbforbes/83d3efab3d8be7926325c044a9aa8329 to your computer and use it in GitHub Desktop.
Script that turns a pdf from pixels into paper near you (well, near me).
#!/bin/bash
# ______ ______ ______ ______ ______
# /\ == \/\ __ \ /\ == \/\ ___\ /\ == \
# \ \ _-/\ \ __ \\ \ _-/\ \ __\ \ \ __<
# \ \_\ \ \_\ \_\\ \_\ \ \_____\\ \_\ \_\
# \/_/ \/_/\/_/ \/_/ \/_____/ \/_/ /_/
#
#
# Script that turns a pdf from pixels into paper near you (well, near me).
# Magic!
#
# Author: mbforbes@cs
#
# (NB: Written a couple years ago; intended for use at UW CSE, but
# potentially useful anywhere you have trouble configuring printing
# but good 'ol `lpr` is reliable from a networked machine.)
#
# argument checking
if [ "$#" -ne 1 ] || ! [ -e "$1" ]; then
echo "Usage: paper <filename>" >&2
exit 1
fi
# settings
user="mbforbes"
server="recycle"
tmpname="~/printme"
printer="psc381"
options="-o fit-to-page sides=two-sided-long-edge"
# copy file
scp "${1}" ${user}@${server}:${tmpname} > /dev/null
# on remote machine...
ssh ${user}@${server} 2>/dev/null << EOF
# print it
lpr -P ${printer} "${options}" ${tmpname}
# and remove it
rm ${tmpname}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment