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 "\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:

Connected to someprinter.
Escape character is '^]'.

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:


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.

How To Image A Computer With Windows 10 Using dism

If you want to image a lot of computers with a clean Windows 10 image, Microsoft  has lots of built-in tools to help do this, but it’s easy to get lost and overwhelmed with their documentation.  To alleviate that headache, I will explain step-by-step how to:

  • create and use an Unattended.xml file that will:
    • skip the initial setup screens
    • create a local admin account
    • activate Windows with a product key
    • (optionally) configure other Window settings
  • capture a deployable Windows 10 .wim file using sysprep
  • deploy the image to multiple computers using the dism command line tool and WinPE
  • (optionally) add drivers to the .wim file

Continue reading “How To Image A Computer With Windows 10 Using dism”

OS X Accessibility Command Line Tool Available On Homebrew

I’m happy to announce that is now available on Homebrew.  A tool for modifying access to assistive devices from the command line.  You can install it like this:

brew install tccutil

The real tccutil (designed by Apple’s engineers), found in /usr/bin, only has one feature: to reset the services (tccutil: Usage: tccutil reset SERVICE).  From a system administrator’s perspective, this is very restricting. Continue reading “OS X Accessibility Command Line Tool Available On Homebrew”

Twin Cities Mac Admins » Meetup notes – April 23, 2015

Featured Presentation Jacob Salmela with Hopkins High School provided our feature presentation Under Cover Of Shell (Scripting). Take a look at Jabob’s website and his GitHub repository. You’ll find he’s solved plenty of issues with scripting. He introduced us to GeekTool, a desktop information display, which he populates with loads of geeklets. And he got a few chuckles explaining his Single-user Mode Intrusion-Detection System with Star Trek red alert klaxon (see slide 35).

Continue reading “Twin Cities Mac Admins » Meetup notes – April 23, 2015”

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”

Twin Cities Mac Admins Presentation: Under Cover Of Shell (Scripting)

On April 23 at JAMF headquarters in downtown Minneapolis, I will be presenting at the April MSP Mac Admins Meetup.  My presentation will cover real-life examples of how scripting can be used.  You don’t need to know a single line of code to enjoy this presentation, but it might pique your interest to learn some! Continue reading “Twin Cities Mac Admins Presentation: Under Cover Of Shell (Scripting)”