Print(script - auto setup (Linux & Mac) )
Introduction
Are you tired of opening the ThinLinc Client app, uploading your file, choosing the right driver, selecting the printer, printing one document, closing it all down again — and then starting from the top for the next document?
We have written a shell script that puts the institute's printers into the normal print dialog of your
own system. After that it is ⌘P, pick printer, print. Nothing else. No app, no upload, no driver
hunting, no VPN and no terminal.
Prerequisite: the compute-hosting setup. This script builds on the SSH access that
imath-setup.shcreates — see the page imath script. Install that first, then come back here.
These scripts are tested on macOS and Linux devices. The device for Windows is not tested.
How it works
The print server print22.math.uzh.ch lives on the institute's internal network. It is not just
firewalled — it is not even in public DNS. You need to be connected to the UZH Network.
Instead, the script sends your print jobs through the jump host you already have SSH access to:
printer_uzh is a small background service. It does not hold an SSH connection open. It only
listens on the local port 6631; the moment a print job arrives, launchd (macOS) or systemd
(Linux) starts one SSH connection, the job goes through, and the connection closes again. While you
are not printing, nothing is connected — you can check that yourself with --status.
Which networks work: eduroam, the institute WLAN, a cable in the office. From outside UZH you need the UZH VPN, because the jump host itself is only reachable from a UZH network.
1. Installation
chmod +x imath-printers.sh
./imath-printers.sh
It shows you every printer of the institute, numbered, and asks which ones you want:
Printers at the institute (52)
1 g25 2 h06 3 h52
4 j 5 j-ps 6 j04
7 j06 8 j08 9 j10
…
Which ones do you want?
a all of them
1 5 9 by number, separated by spaces
h52 j or simply by name
<Enter> cancel
>
Options:
| Command | Effect |
|---|---|
./imath-printers.sh |
pick printers from the list |
./imath-printers.sh --uninstall |
remove everything it installed |
It is idempotent. Running it again adds what is missing, corrects what has changed, and leaves everything else alone. Add more printers later by simply running it again with their names.
2. Everyday use
There is nothing to learn. The printers are in the print dialog of every program, exactly like a printer at home:
Paper size, duplex, trays and the finishing options are the real ones: the script asks the print server for each printer's own capabilities instead of guessing a driver.
If a job sits in the queue instead of printing, you are simply offline. It goes out by itself as soon as the machine has internet again — no need to print it a second time.
3. Documentation
For transparency — the same reason as on the compute page. This is what the script does, so that nobody has to take "just run this" on faith.
3.1 What it creates
| Where | What |
|---|---|
~/Library/LaunchAgents/printer_uzh.plist (macOS) |
the background service, socket-activated |
~/.config/systemd/user/printer_uzh.socket + printer_uzh@.service (Linux) |
the same thing for systemd |
~/.config/imath/printers.list |
the list of printer queues this script created |
| CUPS queues | one per printer you chose, pointing at ipp://localhost:6631/printers/<name> |
That is all. It writes nothing into your shell configuration, installs no packages, and needs no
sudo — CUPS queues belong to your user account.
~/.config/imath/printers.list is the important one: it is how the script knows which printers are
its own. Printers you added yourself are never touched, not even by --uninstall.
3.2 What the installation does, step by step
- Check the jump host.
ssh -o BatchMode=yes imath true. If that fails, the script stops and tells you to runimath-setup.shfirst. Nothing has been changed at that point. - Clean up an older version. If a previous, hand-made setup is still holding the port under an
old name, that service and its
IMATH-…queues are removed first, so the two do not fight over port 6631. - Read the printer list.
ssh imath "lpstat -h print22.math.uzh.ch -a"— the list comes from the print server itself, over the jump host. No tunnel is needed just to read it. - Ask you which ones you want (or take
--all, or the names you gave on the command line). - Install the service. The service comes before the printers, because it is what gives them the local port to talk to.
- Add the printers:
lpadmin -p <name> -E -v ipp://localhost:6631/printers/<name> -m everywhere.-m everywhereis the part that asks the server for the printer's real capabilities. - Check. It sends an IPP request to
localhost:6631and reports whether the answer came back.
3.3 Where the data comes from
Everything comes from the institute's own print server, nothing is hard-coded:
- the list of printers —
lpstat -h print22.math.uzh.ch -a, run on the jump host - each printer's capabilities (trays, duplex, colour, finishing) — from the printer itself, via
-m everywhere - the status you see in
--status—lpstat -p, i.e. what CUPS on your own machine reports
The only fixed values in the script are the server name print22.math.uzh.ch, the SSH host entry
imath, and the local port 6631.
3.4 What it does not do
- No
sudo, anywhere. - No permanently open connection
- It never touches printers it did not create.
- It does not install a print driver:
-m everywhereis IPP Everywhere, which is built into macOS and Linux. - It sends nothing anywhere except your print jobs, to the institute's own print server.
3.5 Uninstall
./imath-printers.sh --uninstall
Removes exactly the printers listed in ~/.config/imath/printers.list, stops and deletes the
printer_uzh service, and removes its log. Your own printers stay, and your SSH setup from
imath-setup.sh stays as it is.
4. When something does not work
| Symptom | Cause and remedy |
|---|---|
Run imath-setup.sh first |
The SSH access is missing. Install the compute-hosting setup, then run this again. |
| The job waits in the queue | You are offline, or not on a UZH network. Connect to eduroam, or switch on the VPN; the job goes out by itself. |
--status says the tunnel does not answer |
Something else is using port 6631, or the service did not start. Run the script again — it rewrites the service. |
| The printer is there but prints nothing | Check in --status whether the queue is idle or disabled. A disabled queue: cupsenable <name>. |
| A printer is missing from the list | ./imath-printers.sh --list shows everything the institute has; add it by name. |
linux
Printing via UZHPrintPlus
Offical ZI Page: UZH Print Plus
Recommended for students.
Printing is possible via WLAN UZH, but not via WLAN EduRoam.
Printing via MATH/DM3L-Print server
Recommended for institute members.
Printing is possible via LAN aswell as WLAN UZH & EduRoam
IMATH-Account required. Create I-MATH Account
Adding Printers
Institute
- Info: Insitute Printers are the ones named after certain rooms (where the printer is located) e.g k30, j11 etc.
- Add Printer: Open a Terminal and type the following command:
- Make sure to insert the real printer name (e.g "k30") in the place holder <printer-name>
sudo lpadmin -p <printer-name> -E -v ipps://print-mac.math.uzh.ch:443/printers/<printer-name> -m everywhere
- Make sure to insert the real printer name (e.g "k30") in the place holder <printer-name>
UPP
- Info: UPP Printers are the ones located on k and j floor (public) e.g k, j, kcolor, jcolor
- Add Printer: Open a Terminal and type the following command:
- Make sure to insert the real printer name (e.g "kcolor") in the place holder <printer-name>
sudo lpadmin -p <printer-name> -E \ -v ipps://print-mac.math.uzh.ch:443/printers/<printer-name> \ -m raw \ -o auth-info-required=username,password
- Make sure to insert the real printer name (e.g "kcolor") in the place holder <printer-name>
Authentication
- Info: Both Institute & UPP Printers require LDAP-Authentication in order to print. (IMATH-Credentials)
- Authenticate: After adding a printer, the first print-job will not ask to authenticate (won't print), just print it again. On the second attempt, you will be prompted for your IMATH-Credentials (shortname+password: same as for MY, MADE, Thinlinc)
- Make sure to tick the box "Remember password", so you will never be prompted for credentials on this printer again.
Booklet Printing
Only available on specific UPP Printer-Queues (jcolor_booklet & kcolor_booklet)
- 1.) Add the following printer:
jcolor_bookletorkcolor_booklet(Adding UPP Printers)- Important: jcolor or kcolor will not work, it has to be the booklet queue!
- 2.) After the printer is added and you are in the Print Dialog, make sure you set the following:
- Paper Setup: A4
- Do NOT select "Booklet" under Handling - Print it as if it was a regular File.
- Paper Setup: A4
Troubleshooting
- You may have discovered that all the Institute Printers are listed in the print-dialog "General"- Tab, even if you haven't added them.
- Printing on them will not work, since there is no way to authenticate!
mac
Printing via UZHPrintPlus
Offical ZI Page: UZH Print Plus
Recommended for students.
Printing is possible via WLAN UZH, but not via WLAN EduRoam.
Printing via MATH/DM3L-Print server
Recommended for institute members. (best Option for MacOS)
Printing is possible via LAN aswell as WLAN UZH & EduRoam
IMATH-Account required. Create I-MATH Account
Setup
- Open Printer Settings > Add Printer > IP-Tab:
- Configuration:
- Adress:
print-mac.math.uzh.ch:443 - Protocol:
Airprint - Queue:
printers/<printername>(Replace <printername> with the actual name of the printer, e.g "k30") - Name: Up to you, has no effect on the configuration (we advise to make it the printername)
- Use: Nothing to do here, Airprint will automatically provide the correct driver.
- Adress:
- Upon the first Print, you will be prompted for your IMATH-Credentials (shortname + PW)
- Make sure to tick the box "Remember this password in my Keychain", this way you will only have to enter the Credentials once.
- Attention: In Case the Authentication-Popup doesn't appear upon the first print, just print the File again - it will then appear.
Booklets
Only available on specific UPP Printer-Queues (jcolor_booklet & kcolor_booklet)
- 1.) Add the following printer:
jcolor_bookletorkcolor_booklet(See above how to add)- Important: jcolor or kcolor will not work, it has to be the booklet queue!
- 2.) After the printer is added and you are in the Print Dialog, make sure you set the following:
- Paper Setup: A4
- Do NOT select "Booklet" under Handling - Print it as if it was a regular File.
- Paper Setup: A4
Overview-Print
Printing I-MATH vs. UZH Printplus (UPP)
At the institute there are two printing solutions available: I-MATH-based and UZH Printplus (UPP)-based.
| I-MATH | UPP | |
| Printer | All printers & copiers | Copiers k, kcolor and j, jcolor. Thinlinc Print Dialog: UZHPrintPlus |
| UZH wide | - | yes |
| Cost | Low. I-MATH pays the infrastructure | High. UZH |
| Scan | Only a few dedicated rooms (not public) | k / kcolor, j / jcolor - use your UZH badge, free |
| Paying | see below | UZH Printplus |
| Requirements | I-MATH Account (or guest) | UZH Account & Badge |
Printing
Please review the specific page:
- UZH Printplus (UPP)
Printer Names
- Printers are named after the room they are in.
- For the big printers on corridors of J and K floors several virtual printers with various configurations are provided. For example:
- jcolor = colored
- j = black/white
- jcolor-booklet = booklet
Public printers
| Printer | Location | Color | Remarks |
|---|---|---|---|
| h52 | Y27 H52 | No | |
| j11 | Y27 J11 | No | |
| k49 | Y27 K49 | No | |
| k49color | Y27 K49 | Yes | |
| j | J floor | No | Stapling, booklet print, A3 format |
| jcolor | J Floor | Yes | Stapling, booklet print, A3 format |
| jcolor_booklet | J Floor | Yes | Only booklet print |
| k | K floor | No | Stapling, booklet print, A3 format |
| kcolor | K floor | Yes | Stapling, booklet print, A3 format |
| kcolor_booklet | K floor | Yes | Only booklet print |
Credit System
All printers of the institute are connected to a central print server, which logs and counts all print jobs. Before a print is sent to a printer, the system gets the page number and job settings, calculates the costs and checks permissions and credits for the sender. After a successful printing, the credits will be subtracted.
| Credits and free printing | black and white | color |
| members of the institute* | free | free** |
| students*** | costs | costs |
- Members of the institute are: Professors, Staff, Assistants (!PostDocs and !PhDs), Guests.
- Assistants need to refill the credit (for free) after printing 100 colored pages per semester.
- Students with 'Hauptfach Mathematik' or "Hauptfach Bio Statistic" get free credits worth 20 SFr. per semester. An I-MATH account is required to print.
- A printjob is counted based on page number, page format (A4 or A3), simplex or duplex and black/white or color.
- Special settings like A3, color or stapling are only available on some special printers like jcolor, k.
Prices for all printers with different settings!
Charging/Checking Credits
- You can view your credit, your settings and your last 50 print jobs in your account admin panel: My Math.
- Users can charge credits at the office Y27K30. The credit can be used immediately.
- Assistants can also write an email to the system support (support@math.uzh.ch), but in this case it can take a while until you receive the credit.
Booklets
Printers / Copiers 'jcolor' and 'kcolor' are capable to fold and stamp printouts to create booklets / brochures.
- Mulitple Copies: DO NOT USE 'copies' (print dialog or via commandline '-n num-copies'). Instead use 'Repeat jobs' under advanced options.
- Up to 16 sheets of paper can be stitched! If you have more they only get folded.
- Printing booklet with only folding (no stamps), might produce outputs where the single folded sheets of paper are one by one and not inserted into each other.
Poster Printing (large)
- ETHZ has outsourced most printing jobs, but you can still print large formats, see here: https://signprint.ch
and here for FAQ on ETHZ's decision to outsource etc: https://ethz.ch/staffnet/en/service/office-supplies-printing-and-mailing/print-publish/futureprint-eth.html - If you are looking for a nearby option: https://posterprinting.bioc.uzh.ch/
Troubleshooting
Text replaced by □
In case you printed on k, kcolor, j, jcolor and the text on the printout is replaced by squares or weird characters, do the following:
- Install GhostScript via Terminal:
- MacOS:
brew install ghostscript(via Homebrew) - MacOS:
sudo port install ghostscript(via MacPorts) - Linux:
sudo apt install ghostscript(Debian, Ubuntu) - Windows:
winget install ArtifexSoftware.GhostScript
- MacOS:
- Convert the PDF:
- MacOS/Linux:
gs -o print.pdf -sDEVICE=pdfwrite -dNoOutputFonts input.pdf - Windows:
gswin64c -o print.pdf -sDEVICE=pdfwrite -dNoOutputFonts input.pdf
- MacOS/Linux:
- Print the Converted PDF:
- Now print the newly generated PDF (in the example it is named "print.pdf")
- The printout should be fine now. If not, please report to
support@math.uzh.ch
windows
Printing via UZHPrintPlus
Offical ZI Page: UZH Print Plus
Recommended for students.
Printing is possible via WLAN UZH, but not via WLAN EduRoam.
Printing via MATH/DM3L-Print server
Recommended for institute members. (best Option for Windows)
Printing is possible via LAN aswell as WLAN UZH & EduRoam
IMATH-Account required. Create I-MATH Account
Setup
- Open System Settings -> Bluetooth & Devices -> Printers & Scanners -> "Add Device" -> "Add manually".
- Make sure to replace <printername> with the actual Printer name: e.g "k30-win"
- Attention: Only queues with "-win" will work!
https://print-mac.math.uzh.ch/printers/<printername>-win
- While adding the printer, you will be prompted for your IMATH-Credentials (shortname + PW)
- Credentials are saved, no need to authenticate again after System-Reboot.
- Press "Next" -> "Finish" -> The printer is ready.
Booklets
Only available on specific UPP Printer-Queues (jcolor_booklet-win & kcolor_booklet-win)
- 1.) Add the following printer:
jcolor_booklet-winorkcolor_booklet-win(See above how to add)- Important: jcolor-win or kcolor-win will not work, it has to be the booklet queue!
- 2.) After the printer is added and you are in the Print Dialog, Print it as if it was a regular File.
- Do not set any Page-Handling options, it will automatically be printed as a booklet.
Example:
thinlinc
The thinlinc environment provides a simple printing solution for workstations and personal devices.
- Workstation:
- Every workspace at the institute provides access to Thinlinc (login with your I-MATH credentials)
- All the Printers are already configured. Press Ctrl+P inside your document to print.
- Personal Device:
- Install the TL-Client: https://www.cendio.com/thinlinc/download/
- Once installed, login with your I-MATH Credentials. (URL=tl.math.zuh.ch)
- All the Printers are already configured. Press Ctrl+P inside your document to print.
- Install the TL-Client: https://www.cendio.com/thinlinc/download/
Create own printer instances
Create own printer instances with personal settings. Such instances are only available via command line.
[user@host
# Create an instance 'jcolor/bw', which prints to 'jcolor', but always in b/w:
$ lpoptions -p jcolor/bw -o ColorModel=Gray
# To use the new instance:
$ lp -d jcolor/bw output.pdf
# Show all printer, incl. instances:
$ lpstat -t
# The local instances are saved under
~/.cups/lpoptions
Printing with Command Line
| Description | Syntax / Example |
| List all printers | lpstat -a |
| Show default printer | lpstat -d |
| Set default printer | lpoptions -d Ex: lpoptions -d k |
lp [-d ] Ex: lp -d h52 paper.pdf |
|
| Print several copies (see notes) | lp -n [-d ] Ex: lp -n 5 paper.pdf |
| Print several copies (see notes) in the order 1,2,3... | lp -o Collate=True -n Ex: lp -o Collate=true -n 5 paper.pdf |
| Print several copies with staples (see notes) | lp -d -o RepeatJob= -o StaplePos=1PLUEx: lp -d j -o RepeatJob=10 -o StaplePos=1PLU exam.pdf |
| Print 2 pages on one site | lp -o number-up=2 Ex: lp -p number-up=2 paper.pdf |
| Printing one sided on a duplex printer | lp -o duplex=None Ex: lp -o duplex=None paper.pdf |
| Printing duplex with turning on short edge | lp -o duplex=DuplexTumble Ex: lp -o duplex=DuplexTumble paper.pdf |
| Printing transparencies | lp -o media=Transparency Ex: lp -o media=Transparency |
Printing with stapling (see note 1) - only j, jcolor, k, kcolor |
lp -d jcolor -o StapleType=StapleON -o StaplePos=(1PLU|1PRU|1PLB|1PRB|2PL|2PR|2PU|2PB) Ex: lp -d jcolor -o Duplex=None -o StapleType=StapleON -o StaplePos=1PLU -o sides=one-sided |
Printing booklet via jcolor_booklet and kcolor_booklet (see note 3) |
lp -d -o print-color-mode=Color|Grayscale Ex: lp -d jcolor_booklet -o print-color-mode=Color -o PageSize=A5 paper.pdf |
Printing booklet via j-ps and k-ps (see note 3) |
lp -d -o BindMode=SaddleStitch -o Duplex=None -o Booklet=Left -o print-color-mode=Color Ex: lp -d jcolor -o PageSize=A5 -o BindMode=SaddleStitch -o Duplex=None -o Booklet=Left -o Finishing=Col -o print-color-mode=Color paper.pdf |
Note 1: Pay attention on combining copies and stapling. If you like to print a PDF (e.g. 4 pages) 10 times, do NOT use the -n parameter. The whole printjob, 4 pages * 10 copies, will be stapled together (only one)!
Solution: Use the 'Repeat Job' option in the advanced tab of the print dialog
Note 2: Do not print many copies at once, because it requires a lot of resources of the printer.
Solution: Use the lpRepeat script instead (with the -s parameter to specify a delay):
$ lpRepeat -d h52 -n 30 -s 15 big_file.pdf
Note 3: Booklet printing can be simplified with the lpBooklet script:
# Color print
$ lpBooklet -d jcolor -f booklet.pdf
# Black & white print
$ lpBooklet -d j -f booklet.pdf
Option values
Duplex: one/two sided print
| Value | Meaning |
| None | One sided |
| !DuplexTumble | Two sided along long edge |
| !DuplexNoTumble | Two sided along short edge |
StaplePos: staple position
| Value | Portrait mode | Landscape mode |
| !PosNone | No staple | No staple |
| 1PLU | Upper left | Upper right |
| 1PRU | Upper right | Bottom right |
| 1PLB | Bottom left | Upper left |
| 1PRB | Bottom right | Bottom left |
| 2PL | Left x2 | Upper x2 |
| 2PR | Right x2 | Bottom x2 |
| 2PU | Upper x2 | Right x2 |
| 2PB | Bottom x2 | Left x2 |
| SDL | Middle x2 | Middle x2 |
Printing with graphical interface (evince PDF viewer)
Stapling
In the print preview dialog select j, jcolor, k, or kcolor and on the tab 'Advanced'
- choose the position of a staple (here upper left corner)
- specify Repeat Job if you need more than one copy
Note: do not specify Copies on the General tab to print several stapled copies! If you do so, all copies are stapled together!
Booklet
In the print preview dialog select jcolor_booklet or kcolor_booklet - these printers are already configured for booklet printing.
Alternatively, select j, jcolor, k, or kcolor and choose the following options:
- Left binding for Booklet Printing on the tab Finishing
- Saddle Stitch for Staple Position on the tab Advanced
Note: booklet printing requires A4 or A5 format.
Printing exams - lpSequential
If you have a personalized exam, one PDF for all students, and you like to print it and the output should be:
- shifted (easy separation), or
- stapled,
than use the lpSequential script (commandline).
- For each exam print, the current page number is shown.
- You can stop a running print job, by pressing Ctrl-C in the commandline.
- If you stopped the printing, restart the printjob by specifing the last printed page + 1.
- : a printer name like
k,kcolor,j, orjcolor. - : If you have an exam pdf with 200 pages (one big file, 25 students, 8 pages per exam) the whole file will be split in jobs as and such part will be printed.
- : '1', if you start from scratch, else the last reported printed page + 1.
- : This is only necessary if you want to be sure that all exams are in exact same order as in the PDF. A reordering might appear inside the printer, if there are multiple print jobs at the same time in the local printer queue. If a delay is specified, this helps to take care that are never more than 2 jobs in the local printer queue at the same time. The amount of delay in seconds depends on the print job size. Start with 5 seconds and stop and increase if it is too short. You can check the local printer queue on the touchscreen at the copier.
# K Floor (k)
$ lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided <file.pdf> k <pages per exam> <start page to print from> <delay in seconds>
# J Floor (jcolor_booklet) - with color
$ lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided -o print-color-mode=Color <file.pdf> jcolor <pages per exam> <start page to print from> <delay in seconds>
Example:
| Staple | lpSequential -o Duplex=None -o StaplePos=1PLU -o StapleType=StapleON -o sides=one-sided exam.pdf k 16 1 0 |
printer 'k', 16 pages per exam, starting at 1, no delay |
| Shifting | lpSequential -o Duplex=None -o sides=one-sided exam.pdf jcolor 8 33 5 |
printer 'jcolor', 8 pages per exam, starting at 33, 5 seconds delay |
- Most exams are single sided, so switch of the default Duplex mode.