12

I tried to print multiple files. However not a single solution posted on the net works.

  1. I tried a right-click using Nautilus actions as described in multiple posts.
  2. Using the lpr command in the terminal and dragging files from Nautilus. Here print opens but files are held, and when the release button is pressed, the window closes without action.
  3. With a script as posted here: Printing a file from the right-click context menu in Nautilus

The only method that works is combining pdf files in pdfmod to a new large file, saving it, and printing it. Not very elegant.

Since no option for multiple works, could the community have a fresh look at right-click printing from Nautilus?

Daniel
  • 121

2 Answers2

15

I just added a right-click menu option that allows you to select multiple files, select Scriptpdf-printer.sh and it'll create PDF files. If you choose another printer name in the script, it should use that instead, but I can't verify that. Older how-tos might not work because we've moved to GNOME 3 which has a few changes. In this case, scripts have been moved from ~/.gnome2/nautilus-scripts to ~/.local/share/nautilus/scripts. Otherwise, everything should work as you would expect.

  1. Install http://apt.ubuntu.com/p/cups-pdf. This package provides a PDF printer that prints to the PDF folder in your home folder, $HOME/PDF.

  2. Open Nautilus and create a folder named PDF in your home.

  3. Press Ctrl+H in Nautilus to show hidden files.

  4. Open ~/.local/share/nautilus/scripts.

  5. Create a new file and call it pdf-printer.sh.

  6. Paste the following:

    #!/bin/bash
    #
    # pdf-printer.sh
    #
    # Print files from the right-click context menu in Nautilus.
    # Place this script in ~/.local/share/nautilus/scripts.
    # The printer to use (as shown in the Printer Configuration
    # gui or in /etc/cups/printers.conf).
    printer=PDF
    echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while read file
        do
            lpr -P "$printer" "$file"
    done
    exit 0
    
  7. Save the file and close it.

  8. right-click the file and choose PropertiesPermissions. Make sure the box is checked to allow executing the file.

It is possible that you have to restart Nautilus for this to work. In that case, you can press Alt+F2 and enter r. Should that not work, then you can press Alt+F2 and enter killall nautilus or restart the system.

Other than that, you should now be able to select files, right-click and use the script from the Script menu.

0

Here's a better approach to use on the script that opens a Zenity dialog to prompt you to choose the printer you need to use:

  1. Install http://apt.ubuntu.com/p/cups-pdf. This package provides a PDF printer that prints to the PDF folder in your home folder, $HOME/PDF.
  2. Install zenity via sudo apt install zenity
  3. Open ~/.local/share/nautilus/scripts
  4. Create a new file and call it print.sh
  5. Paste the following:
#!/bin/bash
#
# print.sh
#
# Print files from the right-click context menu in Nautilus.
# Place this script in ~/.local/share/nautilus/scripts/ (for newer systems).

Get a list of available printers

printers=$(lpstat -p | awk '{print $2}')

Check if there are any printers available

if [ -z "$printers" ]; then zenity --error --text="No printers available. Exiting." exit 1 fi

Use Zenity to present a graphical selection menu

printer=$(echo "$printers" | zenity --list --title="Select Printer" --column="Printers" --height=300)

Check if a printer was selected

if [ -z "$printer" ]; then zenity --error --text="No printer selected. Exiting." exit 1 fi

Print each selected file

while IFS= read -r file; do lpr -P "$printer" "$file" done <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"

zenity --info --text="Printing completed."

exit 0

  1. Save the file and close it.
  2. Add execution permissions: sudo chmod u+x ~/.local/share/nautilus/scripts/print.sh
mpboden
  • 3,046