Ubuntu: Printing with a mouse right-click

Few days back, I came across this nice idea on ubuntu forums. If you want to print a file, why do have to open it and then print? What if you wanted to print multiple files?

Its the small things like these that reminds you the usefulness of scripting. So how do I do it?

cupsdoprint -P PrinterName file1 file2 file3

cupsdoprint is a command line tool to print via CUPS.

So we have our little script around CUPS to print. How do we add it to the mouse context menu? As simple as creating an executable script and dropping into the nautilus script folder. Nautilus passes the context information to the script as variables.

The script file would look like this:

#!/bin/bsh

files=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

cupsdoprint -P MyPrinter $files

exit 0

Name the script “Print”, make it an executable and drop it to your ~/.gnome2/nautilus-scripts folder and happy printing!

Advertisements

4 Responses to Ubuntu: Printing with a mouse right-click

  1. glam says:

    nice!!

    two additions:

    1. Install the package kdelibs4c2a to get this feature.
    2.Use the following command to be complete and for network printers as well

    cupsdoprint -P -U : -o Copies=1,PageSize=A4 $files

    thanks for this.

  2. glam says:

    cupsdoprint -P -U printername username:password -o Copies=1,PageSize=A4 $files

    The printer name is as per the printer name in your printer config in gnome/kde etc.

  3. Pieter says:

    Thanks for the article!! I found that cupsdoprint depends on several large KDE packages. I could do the same with the lpr command, which is installed by default on Ubuntu Karmic and Lucid.

    People that prefer using lpr with your script, can replace the cupsdoprint line with the following:

    lpr -P MyPrinter $files

  4. Pieter says:

    I have extended your script so that it works with filenames containing spaces, and uses lpr rather than cupsdoprint.

    I have posted it here:
    http://www.frenssen.be/content/printing-file-right-click-context-menu-nautilus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: