Printing the Clipboard

Is there a way to bypass another application and print a string variable or the contents of the clipboard directly from a script?

You might be able to pass the contents of the pasteboard to lpr (not sure if it accepts piped stdin, and I’m not near a printer to test):

do shell script "/usr/bin/pbpaste | /usr/bin/lpr"

Results may vary depending on what you’re trying to print. Check out the man page for lpr to see what you can do with it.

Edit: And hey, if it can’t use the output from pbpaste, you can always just kick the pasteboard out to a temp file and print that with lpr.

pbpaste returns the contents of the clipboard correctly but lpr reads file names from the stdin and doesn’t seem to have a switch for getting it to print the contents of the stout.