Nettime mailing list archives

<nettime> 12hr shell script
{ brad brace } on Wed, 2 Jun 1999 07:53:04 +0200 (CEST)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

<nettime> 12hr shell script

From: Robin Stephenson <robin.stephenson {AT} blackwell.co.uk>

------------------------------ cut here ------------------------------
#!/usr/bin/perl -w
# $Id: get12,v 1.1 1999/02/19 17:03:28 trss Exp trss $

# Get an image by FTP, possibly mangle it about, and place it on the
# root window of an X workstation.  Use `--help' for brief docs, or
# read the code.  Intended to be used with Brad Brace's 12hr-ISBN-JPEG
# project <http://www.teleport.com/~bbrace/bbrace.html>: install it in
# your crontab and enjoy.  Based on a shell script from Need To Know
# <http://www.ntk.net/>, and written by Robin Stephenson <quux {AT} usa.net>.

use strict;
use Getopt::Long;
use URI::URL;
use Net::FTP;

## configuration
my($help, $verbose, $email, $URL, $image, $mangle);
GetOptions("help"     => \$help,
           "verbose"  => \$verbose,
           "email=s"  => \$email,
           "src=s"    => \$URL,
           "dest=s"   => \$image,
           "mangle"   => \$mangle);
if (defined($help)) {

# defaults
if (!defined($verbose)) { $verbose = 0 } else { $verbose = 1 };
if (!defined($email))   { $email   = "quux\ {AT} usa.net" };
if (!defined($URL))     {
    $URL = "ftp://ftp.rdrop.com/pub/users/bbrace/12hr.jpeg" };
if (!defined($image))   { $image   = "/tmp/12hr-isbn-jpeg.jpeg" };
if (!defined($mangle))  { $mangle  = 0 };

# this is a bit clunky, and really easy to break  *shrug*  works for me
my($DISPLAY) = $ENV{'DISPLAY'} || "unix:0";

my($XMESSAGE) = '/usr/X11R6/bin/xmessage';
my($XV)       = '/usr/X11R6/bin/xv';
my($CONVERT)  = '/usr/X11R6/bin/convert';

## main program
$URL = new URI::URL $URL;
getfile($URL, $image);
$mangle and $image = processimage($image);

if ($verbose) {
    my($date)=`date +"%l:%M %p %A %d %B"`;
    message($date, "Updated root window from\n$URL");


## subroutines
# Print some basic usage information.
sub usage () {
    print STDERR << "EOF";
get12  [-verbose] [-email="your\ {AT} email.here"] [-src="URL of image"]
                  [-dest="/tmp/image.jpeg"]  [-mangle]

    --email        your email address: used to log you in to anonymous FTP
    --src          an FTP URL of an image file (see below)
    --dest         where the image file will be stored locally
    --mangle       post-process the image after it arrives (see source)

    URLs for the 12hr-ISBN-JPEG project are as follows:

# Get the current picture from $URL by FTP and place in $dest.
sub getfile ($$) {
    my($URL, $dest) =  {AT} _;

    if($URL->scheme ne 'ftp') {
        die("Not an FTP URL: $URL\n");

    my($site) = $URL->netloc;
    my($file) = $URL->path;

    my($ftp) = Net::FTP->new("$site");
    $ftp->login("ftp", "$email");
    $ftp->get($file, $dest) or die("Couldn't get $URL: $!\n");

# Display a message in an X window (click to dismiss).
sub message ($$) {
    my($title, $message) =  {AT} _;

    # primitive escaping of special characters
    $title   =~ s/\"/\\"/g;
    $message =~ s/\"/\\"/g;

    if (-x $XMESSAGE) {
        # This is a bit ugly: xmessage idea is from Jamie Zawinski's cid hack.
        my($command) = << "EOF";
/usr/X11R6/bin/xmessage -display $DISPLAY -name "$title"                            -xrm '*Font: -*-lucida-medium-r-*-*-*-190-*-*-*-*-*-*'                          -xrm   '*Foreground: black'                                                     -xrm   '*Ba

ckground: lightgreen'                                                -xrm   '*Command.Background: red'                                               -buttons ''                                                                     -xrm   '*Command.horizDist

ance: 25'                                             -xrm   '*message.borderWidth:0'                                                 -xrm   '*Translations: #override <BtnDown>: exit(0)'                            "$message" &
    } else {
        warn("xmessage not found in $XMESSAGE\n");

# Mangle an image from the $image file in some interesting
# NON-DESTRUCTIVE way.  Return the filename of the modified image.
sub processimage ($) {
    my($image) =  {AT} _;

    # add a blue tint
    if (-x $CONVERT) {
        system("$CONVERT $image -colorize 0/0/40 $image.blue");
    } else {
        warn("no conversion performed\n");

# Set the root window image to the image contained in the $image file.
sub setbackground ($) {
    my($image) =  {AT} _;

    if (-x $XV) {
        system("$XV -display $DISPLAY -quit -root -rmode 5 -maxpect $image");
    } else {
        warn("xv not found in $XV\n");



#  distributed via nettime-l : no commercial use without permission
#  <nettime> is a closed moderated mailinglist for net criticism,
#  collaborative text filtering and cultural politics of the nets
#  more info: majordomo {AT} desk.nl and "info nettime-l" in the msg body
#  URL: http://www.desk.nl/~nettime/  contact: nettime-owner {AT} desk.nl