Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Print selected text from browser via AppleScript Web Browsers
I have been reading MacOSXHints for quite some time. In an effort to contribute and not just leech, here is a hint that I find useful daily. I miss the "Print Selection" option found in some browsers on Windows. I find this useful to quickly print directions, recipes, or anything else where I want an unformatted plain text print out.

Combining some AppleScript and Terminal commands, I created an AppleScript addition that allows me to select text in my browser (currently Camino), click one button, and send it to my default printer. Two items need to be placed on your system to get this to work:
  1. Shell script to send the text string to the default printer.
    #! /bin/sh
    pbpaste | lpr
    I saved this as ~/Documents -> Scripts -> sel_lpr.sh
  2. An AppleScript to capture the highlighted text and send it to the clipboard:
    tell application "Camino"
      activate
      tell application "System Events" to keystroke "c" using command down
    end tell
    do shell script "~/Documents/Scripts/sel_lpr.sh"
    This is, of course, saved in ~/Library -> Scripts -> PrintSelected.app.
Now when I select some text, I just select this AppleScript and it shoots it to the default printer. A more elegant way would be to call the AppleScript from a bookmarklet, but I have not gotten around to that yet. Hope this helps someone else...

[robg adds: Remember to make the shell script executable with chmod a+x sel_lpr.sh from within the Scripts directory (or wherever you saved it).]
    •    
  • Currently 2.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[19,605 views]  

Print selected text from browser via AppleScript | 8 comments | Create New Account
Click here to return to the 'Print selected text from browser via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Print selected text from browser via AppleScript
Authored by: MacParc on Oct 12, '06 07:46:38AM
The Print Selection Service adds a "Print Selection" command to the Services menu that allows you to print the current selection in any application: Download 'Print Selection Service'

[ Reply to This | # ]
Print selected text from browser via AppleScript
Authored by: Lutin on Oct 12, '06 08:56:36AM

I was gonna post the exact same thing.
Print Selection Service works very fine for me, and has quickly become a 'must have'.



[ Reply to This | # ]
Print selected text from browser via AppleScript
Authored by: TheCrunge on Oct 12, '06 09:19:59AM
For an AppleScript like this, you don't need two separate files ( a separate shell script called by the AppleScript). You can replace:
do shell script "~/Documents/Scripts/sel_lpr.sh"
with:
do shell script "pbpaste | lpr"


[ Reply to This | # ]
Re: Print selected text from browser via AppleScript
Authored by: Uncle Asad on Oct 12, '06 11:18:09AM

Of course, in Camino's case, you can simply select the "Print Selection Only" checkbox in the Camino pane of the Print dialogue ;)



[ Reply to This | # ]
Re: Print selected text from browser via AppleScript
Authored by: PancakeMan on Oct 12, '06 01:36:14PM

On another note: so THAT's where you can set headers and footers for printing in Camino! Cool!



[ Reply to This | # ]
Print selected text from browser via AppleScript
Authored by: stublock on Oct 12, '06 12:32:51PM

Camino has this feature built in. Select Print, then on the 3rd menu down (Copies & Pages) select Camino, then select " Print Selection Only" and print.



[ Reply to This | # ]
Print selected text from browser via AppleScript
Authored by: csolallo on Oct 12, '06 10:10:19PM
Since Camino is a Cocoa based app, it has services enabled. So, another option is to select the text you want then click Camino -> Services -> TextEdit -> New Window Containing Selection. You can then print your selection from TextEdit.

I like doing it this way because I then have the option of saving the selection as a text file which Spotlight graciously indexes for me.

[ Reply to This | # ]
Print selected text from browser via AppleScript
Authored by: jonesy on Oct 13, '06 12:40:25PM

As with Camino above. Firefox does this as well.

Choose the Firefox item in the print dialog. Check "Print Selection Only".

---
Grrrr!!!!!



[ Reply to This | # ]