Using "day of the week" to print

print calendar

Recently we talked with someone who wanted to print to one printer on weekdays and another printer on nights and weekends. Their question was about us doing custom programming for RPM Remote Print Manager® ("RPM")

RPM doesn’t have this facility built-in, but it is easy to accomplish with a small amount of scripting. We have decided to make available a sample script you can adapt to use for your own needs.

We usually do our custom programming in Python for several reasons:

  1. It’s a regular programming language with excellent support for many operations people need to do
  2. We can easily communicate with RPM using our RPC library: https://github.com/gddc/rpmcli

However, we had batch files already for other purposes and found we could use common techniques to accomplish this task as well. We'll talk about that batch file in this post.

I called the script printbyday.txt. Download the file by right-clicking on that link and selecting "save as" to put it in your downloads folder or wherever you choose. Edit the file in a text editor such as Notepad++ or Notepad; any plain text editor will do. Be sure to change the file extension from ".txt" to ".bat"

Ultimately you will use a filter action to run this script. We have lots of documentation on that already.

Let’s dissect the logic of this script section by section.

Using pylpr

We have bundled a program called pylpr.exe with RPM since version 6.1.0.437 dating back to June 2016. This program supports the same command line options as the Microsoft LPR program although it is far more capable.

In our script we use pylpr. If you prefer to use the Microsoft LPR you may need to install it first. Go to line 4 and change where the "pylpr" variable is assigned, to use the path for the Microsoft program instead.

While we’re talking about the Microsoft LPR let me offer two notes for your consideration:

  1. The Windows LPR is slow out-of-the-box without applying a registry hack.  Search the Microsoft website for "usenonrfcsourceports" for additional details.
  2. If you are using the 32-bit version of RPM on a 64-bit version of Windows and wish to use the Windows LPR, the path you use should be "%windir%\Sysnative\lpr.exe". You need to specify that value to ensure the script will find the lpr.exe program, since it resides in the 64-bit system32 directory.

Day of the week

We use the Microsoft program "WMIC" to fetch the day of the week in numeric form. Sunday is zero, Monday is 1, and so on. If the current day falls on Monday through Friday, we’ll enter the Weekday logic. Otherwise, we’ll go to the Weekend logic.  The weekend logic requires no further scripting and simply prints to Printer1.

Time of day during the week

In the weekday logic, we’ll evaluate the current hour which was assigned to the variable HH in a previous line. If the hour falls between 7 AM and 4 PM, Printer2 is used. During nights and weekends, we want to send our prints to Printer1.

We’ve designated Printer1 as the "Weekend" printer and Printer2 as the "Weekday" printer only because that’s how the the problem was presented to us.

Final print

This script depends on there being queues in RPM called Printer1 and Printer2. Those are merely for illustration. We assume you would modify the script to use more descriptive queue names... unless you have giant "1" and "2" stickers on your printers. If you do, we’d love to see a picture.

Conclusion

We intended this example not to show that RPM has a specific ability to deal with dates for conditional logic, but that many problems have a simple solution using basic programming skills.

To learn more about taking a substring from a DOS variable, search on "dos string manipulation".

I found a lot of coverage online for batch file programming and it's hard to know which to recommend. I can suggest that you start with this search: "ms-dos batch file programming".

Please note that this is the request we initially received. Part of the purpose of this article is to demonstrate that the original parameters boil down to a simple solution, without custom programming or complicated setup.