Skip to content

Instantly share code, notes, and snippets.

@karlredgate
Last active November 19, 2022 18:49
Show Gist options
  • Save karlredgate/c7ff51c992cc6adbb01c36ee1f73f998 to your computer and use it in GitHub Desktop.
Save karlredgate/c7ff51c992cc6adbb01c36ee1f73f998 to your computer and use it in GitHub Desktop.
Print postscript file duplexed to printer with bash and awk only

Print a Postscript File Duplexed with only Bash and Awk

The awk script is using heuristic to determine where to insert the Duplex commands in the file.

The bash script is using the bash "feature" of sending to a network socket using the fake device paths that are builtin to bash.

#!/usr/bin/awk -f
{ print }
/%EndFeature/ {
print "%%BeginFeature: *Tumble False"
print " (<<) cvx exec /Tumble (false) cvx exec (>>) cvx exec setpagedevice"
print "%%EndFeature"
print "%%BeginFeature: *Duplex True"
print " (<<) cvx exec /Duplex (true) cvx exec (>>) cvx exec setpagedevice"
print "%%EndFeature"
}
#!/bin/bash
# duplex command is the awk script in your PATH
PRINTERADDRESS=169.254.1.1
duplex < "$1" > /dev/tcp/${PRINTERADDRESS}/9100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment