Printing with AppleScript + Processing/Java

For one of the recent project, I have to write an application that generate QR code and send the generated image/file for printing.

Java printing API
Since I used processing as the development platform, I tried Java Printing API. The original plan was:

  1. Use the XZing library for code generation (
  2. Using the ecoder class in the core library, a bitArray will be returned, basically it is a 1d array recording 0 & 1s, so it could be easily translated to PImage using the pixel access class.
  3. Draw the generated QRCode image to the canvas or an offscreen PGraphics.
  4. Save the image file and send the file to print.

The constrain for using Java printing API was the default PDF output library comes with Processing can only produce images that in 72dpi, and it is difficult to utilize the print options of printers (e.g. fit to page, media size…etc).

Thus despite of the initial success, this method was abandoned.

Apple script and printing
The good news is that for this project we are planning to use Mac OS X platform. After fighting with CUPS printing server back in Ubuntu time, I am planning to use BASH script to accomplish this.

Bash + Java
Before doing anything further, the first thing to test is whether Java can trigger and execute a bash script, then write a bash script that will actually print a file.

I knew that if you type “open ~/Desktop” in OS X terminal, a Finder window will actually pop up showing the content on the Desktop folder, thus I wrote a script like this.

open Desktop

and saved the above text in, to test it I have to first make it executable

chmod +X

Then in Processing I simply put the following lines and ran it. (Reference:

          theProcess = Runtime.getRuntime().exec("java");
      catch(IOException e)
         System.err.println("Error on exec() method");

And it worked!

Print script
The next step is to find references for writing bash script that will actually print in OS X, and luckily I found some useful references

Basically you can simply write a bash script like the following for printing

ls -d PrinterName -o landscape -o fit-to-page path_to_file

In order to find the printer name, you can run the following command in terminal

lpstat -p -d

It worked like a charm until I tried with another printer (Hiti P510L)

Setting the media size
No matter how I changed the image size the printer was simply not printing. It kept showing “unsupported paper size” error. The reason for not trying this option in the beginning was that I’ve already set the default options through CUPS web interface (localhost:631), by combining this with the “-o fit-to-page” options, it should automatically convert and print. However it wasn’t the case.

Out of desperation, I tried listing and specifying the size and orientation in the bash script.

To list the supported media size, use the following command

lpoptions -p printer -l

In the actual bash script I wrote the following

lp -d printerName -o portriat -o fit-to-page -o media=6x4 filename

And it worked!

Problem solved!

PD Session- Integrate EduTech in Classroom

“Open your laptop and login to ManageBac” is almost the equivalent to “turn to page xx of the textbook”  the school. However is the potential of laptops being fully exploited in our classroom? Is it being used as a “typewriter and encyclopedia”?

ICT and Technology
As a technology teacher and teacher librarian, this is a typical conversation in the tech lesson.

“Mr. Lin, my computer doesn’t work”
“Well, it’s not really about the subject, can we talk about it later?”
“But it is about my COMPUTER, it is TECHNOLOGY”

What does IB says about technology and IT?
MYP Technology and ICT- OCC_m_g_mypxx_fcl_1103_1_e

From the document:
In most cases, technology teachers are given responsibility for providing students with the teaching and learning experiences to help them develop ICT literacy. The teaching of ICT skills should not be confused with or take the place of a computer technology course. ICT is simply a tool used to develop computer technology solutions using the Design Cycle.

Also from the document:
Depending upon the school resources, ICT should be used whenever appropriate:

  • As a means of expanding students’ knowledge of the world in which they live
  • As a channel for developing concepts and skills
  • As a powerful communication tool.

ICT as a powerful communication tool for collaboration for developing concepts and skills with international mindedness.

Yes, this is a long title but it actually illustrate how we can use the laptop effectively in the classroom. I will be demonstrating how we can use Google Site and Google+ in the classroom for collaboration.

Google Site/Wordpress for teachers
Google site can be used as a repository for sharing essential documents, references for lessons and an electronic notice board for your class.
Here’s an example of how a subject site can look like
(Using wikispaces)
(Using Google site)

Other references
40 ways to use google app in classroom
How to insert google docs/drive on google site
Using Google+
Using Google Form

Google+ Community
Instead of using facebook, Google community is a better way to create a “learning community”.

11 steps to create Google+ community for your class

One more thing- AirServer
The above tools are very handy when it comes to sharing. AirServer allows users to share their screen that supports airplay to be shown on your laptop.
*Disclaimer, I’m getting a 3 days extension if you download from here.