Run PJL Commands From A Shell Script

I love learning obscure and under-utilized things in the tech world; PJL commands fit that bill.  You can use PJL commands to get and set printer preferences.  This includes getting the page count, setting the serial number, and changing the LCD display message.

I was recently tasked with evaluating our printer usage to determine if we could save money by removing low-usage printers.  Like many companies, the majority of our printers were HPs, and we were on a tight budget, so something like Papercut was out of the question.  I also wasn’t about to go around to each printer and print out the usage report, nor did I want to enter the Web interface of every printer to manually get this information.

Thankfully, I had already learned how to use PJL commands to set the serial number.  During that time, I also learned that you could get information from the printer using the INFO command.

There are two parts to this.  First, is a script I made that will accept an IP address as an argument and then use telnet to access the printer, run the PJL command, and then print the output back to the terminal.

The most basic of scripts would look like this:

 { echo -e "\033%-12345X@PJL";
 echo -e @PJL INFO PAGECOUNT;
 echo -e "\033%-12345X";
 sleep 5; } | telnet ${1} 9100 | sed -e 's/\r$//'

This will run the PJL commands using the escape character when you pass an IP address as a first argument to the script.  You could also just replace the ${1} with an IP address, but it’s nice to have it a bit more versatile.

The PJL commands use a special escape character which initially gave me a big headache until I figured out how to enter it on a Mac.  I have learned (thanks to od -bc) that this is just ASCII code 033, so I added that into the script to make it more copy/pasteable.  So the script:

  • echo‘s the commands I want to run
  • pipes them into telnet using the first argument passed to the script–which will be the IP address of the printer–using port 9100
  • removes the carriage return characters via sed
  • sleeps for a few seconds to ensure the output is displayed

This will result in some output like this:

Trying 10.20.10.201...
Connected to someprinter.
Escape character is '^]'.
@PJL INFO PAGECOUNT
3733

I ran this once a month and and then compared the page counts to see how often it was being printed to.

If you wanted to reset the counter to zero after each month, you could also do that by adding in this command:

@PJL SET PAGES=0

In my case, it was more important to know the lifetime usage of the printer since most printers had been around for a decade or more.

Merge PDFs Natively With A Right-Click In OS X

UPDATE: If you installed this script today (2016-08-15), you may need to update it.  I added a line in the script that should prevent duplicate pages from being appended.

There are plenty of apps that help you merge PDFs into a single file, but if you want something faster with a “native” feel, you can set up an OS X service to quickly merge selected PDFs simply by right-clicking them. Continue reading “Merge PDFs Natively With A Right-Click In OS X”

Automatically Change .om to .com To Prevent Malware

Malcontents are sneaky.  In their latest ploy, they are counting on you misspelling “.com” so they can send you to one of their fake domains.  So instead of going to netflix.com, you end up at netflix.om–a phony site determined to infect you with malware.  If you are not paying attention, you might not realize you are on the wrong domain. Continue reading “Automatically Change .om to .com To Prevent Malware”

Convert DOCX to PDF Natively With A Right-Click

Microsoft Office for OS X is usually very sluggish and slow.  This is one reason I don’t like working with DOCs or DOCXs in OS X.  Yes, you can easily view the document using QuickLook (pressing the Space bar while the file is highlighted), but if you actually want to open the file and manipulate it, you need to either buy Office, or get an open source alternative.

Download a pre-built workflow (or create your own by following the steps below).

Continue reading “Convert DOCX to PDF Natively With A Right-Click”

Quickly Download Or Install Common Apps Without Going To The Website

While helping friends and family with their computers, I often need to download an app they don’t have or update it to the latest version–something I don’t really want to spend my time doing.  This is definitely a first-world annoyance for me, but I always have fun making the computer do my laborious tasks for me, which frees up more time to do the things I enjoy. Continue reading “Quickly Download Or Install Common Apps Without Going To The Website”

How I Went Paperless And Clutter-free For $32

Ever since I discovered Dropbox, I felt weighed down by the clutter of physical documents.  I use it for all of my digital documents.  After a while, physical documents and pieces of paper began to get on my nerves.  It was much easier to have searchable PDFs that I could access anywhere.  To that end, I wanted to be able to convert any physical document I received into a searchable PDF.  See the video below for the entire workflow in action. Continue reading “How I Went Paperless And Clutter-free For $32”

Automatically Sort Dropbox Camera Uploads Based On Their Geographical Data

I have been a long time fan of using Dropbox to manage my photos, even with the release of Photos.  I have especially liked it ever since Dropbox enabled Camera Uploads from their iOS app.  With my latest script, I can now upload photos from my iPhone and have them automatically sorted into folders based on the city they were taken in.

To accomplish this, OS X’s Spotlight (mdls ) is used to extract the coordinates from the photo, and then those are sent to Google to get the city (or the state, address, and more). Continue reading “Automatically Sort Dropbox Camera Uploads Based On Their Geographical Data”

Bash Script: Fix Paused Printers In OS X

You need an administrator password to un-pause a printer in OS X.  It is possible to add a user to the lpadmin group.

sudo dseditgroup -n /Local/Default -o edit -a username lpadmin

This will give them rights to the printer, but if your users aren’t admins of their machines, this might not be something you want to open up.  This is the case for the school I work at.  My solution was to create a LaunchDaemon that would automatically detect and un-pause paused printers. Continue reading “Bash Script: Fix Paused Printers In OS X”