Skip to content

Instantly share code, notes, and snippets.

@bevancollins
Created November 30, 2011 08:31
Show Gist options
  • Save bevancollins/1408432 to your computer and use it in GitHub Desktop.
Save bevancollins/1408432 to your computer and use it in GitHub Desktop.
HP (and compatible) printers have a feature to display abitary text in the LCD screen. This script will send a random fortune message to a printer. Setup a cron job to send a new message each hour.
#!/usr/bin/perl
use IO::Socket;
use Text::Wrap;
$ip = shift || die "$0 <ip address or name> [display columns] [display rows]";
$columns=20;
$columns = shift;
$rows=4;
$rows = shift;
$Text::Wrap::columns=$columns;
$padding=' ' x $columns;
while(1) {
$_=`/usr/games/fortune -s`;
$_=wrap('', '', split);
s/$/$padding/mg;
s/(.{$columns}).+$/\1/mg;
s/\n//g;
last if (length($_) <= ($columns * $rows));
}
$sock = new IO::Socket::INET (
PeerAddr => $ip,
PeerPort => '9100',
Proto => 'tcp',
);
die "could not create socket! $!\n" unless $sock;
print $sock "\033%-12345X\@PJL RDYMSG DISPLAY = \"$_\"\r\n";
print $sock "\033%-12345X\r\n";
close $sock;
print "$_\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment