Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Tuesday, September 20, 2011

Duplex Printing from the Command Line to an HP LaserJet Printer

My department has several HP LaserJet printers available to access within the department via LPR and SMB. However, if you are working from a personal laptop connected to the university wireless, those servers will not be available to you. Instead, you must print by piping your documents through SSH to a department server that does have access.

Unfortunately, doing duplex printing (i.e., two-sided printing) to an HP LaserJet printer from the command line is not trivial. So, using the GSview documentation as a guide, I put together a small bash script (available for download as hplj_duplex_print) that does the trick.
#!/bin/bash

declare -a input_file
if test $# -eq 0; then
    input_file=("-")
else
    input_file=("$@")
fi

( echo -e "\e%-12345X@PJL JOB"
  echo "@PJL ENTER LANGUAGE = POSTSCRIPT"
  echo "<< /Duplex true /Tumble false >> setpagedevice"
  gs -sDEVICE=psmono -sPAPERSIZE=letter -q -sOutputFile=- \
    -dNOPAUSE -dBATCH "${input_file[@]}"
  echo -e "\e%-12345X@PJL EOJ"
  echo -e "\e%12345X"
  ) | lp -d your_HP_printer_spool_name
You should replace the your_HP_printer_spool_name with your printer's spool name. You might want to tweak some of the options (details below), but the general structure will remain the same. The opening and closing escape sequences communicate to the HP LaserJet printer that a PostScript file is coming. Then the setpagedevice PostScript directive instructs the printer to use its duplex module.

Regarding tweaking:
  • Again, make sure to change your_HP_printer_spool_name to your spool name. You may also want to change lp to lpr, but you will likely have to change -d to -P then.
  • You may want to change the gs (GhostScript) options to suit your purposes. For example, you can change the psmono device to one of the other GhostScript devices like psgray or psrgb.
  • The Tumble switch determines whether to do short-edge (true) or long-edge (false) duplex printing, and so this script defaults to the latter case. If you prefer vertical flipping, change the /Tumble false to /Tumble true. You might also make this a configurable command-line switch on the script.

Wednesday, February 16, 2011

More Quick Reference Cards

Remember that time when I was quick reference card happy [1, 2, 3, 4, 5]? Today, I accidentally found another good quickref card blog post by someone else (Refcards by Michael Goerz; see the original post for the source code and other versions of these cards):He also includes a few quick reference cards not written by him (Subversion (SVN), GDB, GNU Emacs, MySQL).

Friday, February 11, 2011

Scripts to get Mercurial up and running on OSU CSE machines (SunOS and Linux)

UPDATE: A day after I posted this, Mercurial and Python (and Git) were added as optional subscriptions for users of these machines. So login to your desired machine and execute subscribe, then select MERCURIAL and whatever PYTHON is available (version 2.4.x or higher). Quit subscribe to save your changes, and re-login (of course, you can also do the same thing with GIT).
If you are a student, staff member, or faculty member in the Computer Science and Engineering department at The Ohio State University, you may have found yourself wanting to use a DVCS like Mercurial (hg) for SCM. Unfortunately, the version of Python that comes bundled on these enterprise systems prevents installing Mercurial, and some other issues on the SunOS system (like the lack of round() in the math library) prevent building a recent version of Python 2 that is needed for installing Mercurial. There are ways around this mess, and I have done my best to automate them within a script.

So give it a shot:Download the appropriate script to your desired target machine. Next, edit the script (e.g., using pico, nano, vi, or emacs) to verify that the INSTALLDIR location at the top of the script is what is desired – if you are going to run the script on both types of machines, your INSTALLDIR must be different in the two scripts. Then run the script on the machine (e.g., ./install_hg_osu_cse_sun.sh) and follow the instructions. The script is interactive, and so you will be able to manage its behavior as it runs. Be sure to follow its instructions at the end about setting your PATH and PYTHONPATH; if you ran the script on both types of machines, you will have to be clever in your script RC/profile file to set these differently based on the machine you are on – I recommend using uname to detect the different machine type.

After that, you should have a working Mercurial. In the Linux script, you may adjust the Mercurial and Python 2 versions downloaded, but in the SunOS script, you need to leave the Python 2 version alone as later versions of Python will not build on the SunOS machines (due to the problems with the old math library). On either machine, if you are adventurous, you can use the installed Mercurial to clone the stable Mercurial repository (hg-stable) and keep your installed Mercurial up-to-date with the very latest stable version.

Friday, February 08, 2008

I've finally done it...

After 15 years, I've finally done it.

I've put set -o vi into my profile.

(Sam Cooke's "A Change Is Gonna Come," performed by James Taylor as in the West Wing episode, plays in the background)

Wednesday, August 29, 2007

Viewing man pages and text files in Skim

As discussed on the Skim wiki, it is possible to view man pages (and more) nicely formatted as a PDF in Skim.

If you use bash, try adding these lines to your .bashrc:
function skimcat () { cat $* | enscript -p - | open -f -a Skim; }
function manp () { man -t $* | open -f -a Skim; }
Alternatively, if you use tcsh, try adding these lines to your .cshrc:
alias skimcat="cat \!* | enscript -p - | open -f -a Skim"
alias manp="man -t \!* | open -f -a Skim"
Then you'll be able to do skimcat to cat files to Skim, and you'll be able to use manp to view man pages formatted in Skim.

NOTE: You can actually pipe anything that is PostScript (or PDF) formatted to Skim (via the open command shown above).

Monday, July 23, 2007

The Quick Reference Site (Cards and Books)

UPDATE 3: I did find the source of that regular expression card at Gordon McKinney's Pro IT Blog. Well, it's not a LaTeX source, but it's at least in letter format.

UPDATE 2: I found another good list of quick reference cards at the plantOzh blog. It includes a a regexp card, Perl 5 booklet, and CSS cards (1.0, 2.0). Yes, these cards are archived at the blog, so all of the commentary below still applies.

UPDATE 1: It's also annoying when someone simply archives existing quick reference cards because sometimes those archives use A4 paper. If these were linked to their origins, the source code (perhaps LaTeX) might be available, making a conversion to letter paper easy.

Lately, I have been quick reference happy [1, 2, 3, 4]. I cannot explain why, but I suddenly want to surround myself with quick references.

I think I found a great new quick reference resource. It's The Quick Reference Site, which features quick reference cards, e-books, and other papers and tutorials. From the site:
Throughout the years I have collected a huge pile of documents that deal with almost every aspect of software development. The purpose of this site is to centralize this information and to make it available to everyone who may need it or shares my passion on this subject. There are still a lot of documents in my "archive" that I like to share with you all.
At the moment this site represents only a fraction of what I want to provide, so a lot of work still needs to be done. As a result, you should consider this site as a work in progress. I'll try to keep you updated on the most challenging, powerful and continuously evolving software technologies of the moment. I hope that especially Java and C++ fanatics (like myself) will find some valuable information over here.
As far as I can tell so far, the author archives quick references that he has found over time and links us, the readers, to those archives. The advantage of this is that it minimizes the chances of broken links. The disadvantage is that the archives may not be the most recent versions. Additionally, if this site ever goes down and our bookmarks point there, those bookmarks will be broken.

Some quick reference cards that I want to point out (if you go to his list, you can also read descriptions of these programs):

So, that's fun.

On a slightly unrelated note, you can also check out Hawk Wings to find a QuickSilver quick reference and the QuickSilver user manual.

Thursday, July 19, 2007

Hot Key References

NOTE: The two updates below may serve as good LaTeX examples featuring the use of multicol.

UPDATE 2: I have used the Thunderbird list to make a Thunderbird quick reference PDF (LaTeX source available).

UPDATE 1: I have used the Camino list to make a Camino quick reference PDF (LaTeX source available).

I have been posting about quick references a lot lately [e.g., 1, 2]. I found another good quick reference site, allhotkeys.com. It has lots of software hotkey quick references. For example,
So that's potentially helpful. But right now the pages are really slow to come up, so I have no idea what they look like. Nor do I know if I can easily get them onto a landscape sheet of paper that I can tape to the wall somewhere...

Wednesday, July 18, 2007

MATLAB Quick Reference Cards (and more)

UPDATE: I list an AMSTeX reference card below. There is also an AMSLaTeX reference card available at refcards.com.

This is meant to be a follow-up to the "TeX Reference Card (and others)" post.

I found a list of a bunch more quick reference cards, which include applications/packages like MATLAB, MATLAB toolboxes, Perl, MFC, MySQL, Linux, UNIX, Vi, Vim, Windows, AMSTeX, TeX, and a bunch more...

However, I was just looking for MATLAB quick reference cards. So, here are these (some of which did not come from the above site):
So, that's nice. I recommend one of the bottom two [i.e., 1, 2].

Wednesday, June 27, 2007

Pine, PASSFILE, all-patch, and Thunderbird 2.0 IMAP keywords

Thunderbird 2.0 has been released! It's fast and finally supports an arbitrary number of custom IMAP keywords (IMAP keywords are similar to the labels used in GMail). I'm thrilled about this.

However, regardless of how wonderful Thunderbird gets, I will always keep PINE around (which has supported IMAP keywords for a long time).

When I build PINE for my systems, I usually pick up a few of the most popular patches as well. I never noticed that there was an all of the above patch that packages ALL of the most popular patches, new features, and bug fixes. I think this is pretty exciting too.

To build PINE with PASSFILE support (i.e., support for saving passwords to file), I recommend using the infinite ink instructions:
#!/bin/sh
./build clean
./build 'EXTRACFLAGS=-DPASSFILE=\".pine.pwd\"' osx
# ^^^
# platform
You can find a list of platforms in the doc/pine-ports file. Some common ones include (see the document for any special build instructions):
    BSD (original BSD 4.3 from U.C. Berkeley)
bsd BSD 4.3

BSDi
bs3 BSDi BSD/386 Version 3 and Version 4
bs2 BSDi BSD/386 Version 2
bsi BSDi BSD/386 Version 1

Cygwin
cyg Cygwin environment under Windows

HP-UX
hpx HP-UX 10.x
hxd HP-UX 10.x w/ DCE
ghp HP-UX 10.x using gcc
hpp HP-UX 8.x and 9.x
shp HP-UX 8.x and 9.x w/ TCB
gh9 HP-UX 8.x and 9.x using gcc

Linux
lnx Linux using crypt from the C library
lnp Linux using PAM
slx Linux using -lcrypt for crypt()
sl4 Linux using -lshadow for crypt()
sl5 Linux using shadow passwords
ldb Debian Linux
lmd Mandrakelinux
lrh RedHat Enterprise and RedHat 7.2 or later
lsu SuSE Linux

Macintosh
osx Macintosh OS X
ox2 Macintosh OS X 10.2 and earlier

NetBSD
neb NetBSD

OpenBSD
bso OpenBSD w/ shared-lib

QNX
nto Neutrino

SCO
sc5 SCO Open Server 5.x
go5 SCO Open Server 5.x using gcc
sco SCO Unix
gsc SCO Unix using gcc

Sun Solaris (Solaris 9 is the same as SunOS 5.9)
gs5 Sun Solaris >= 2.5 using gcc
soc Sun Solaris >= 8 using Sun C
gs4 Sun Solaris <= 2.4 using gcc
so5 Sun Solaris >= 2.5 (try soc or gs5)
so4 Sun Solaris <= 2.4

Sun SunOS (This is pre-Solaris SunOS)
sun Sun SunOS 4.1
ssn Sun SunOS 4.1 w/ shadow passwords
gsu SunOS 4.1 using gcc
s40 Sun SunOS 4.0

System V Release 4
sv4 System V Release 4

Windows
wnt Windows NT 3.51
Happy mailing!