Created
September 8, 2010 22:29
-
-
Save squeeks/570955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
=head1 Overview | |
This script will download the current Earth Observatory Image of The Day from NASA, | |
and set it as your wallpaper. | |
=head1 Dependencies | |
L<WW::Mechanize>, which you can install through CPAN. | |
=cut | |
use WWW::Mechanize; | |
=head1 Configuration | |
Just one - the folder where downloaded wallpapers will live. | |
=cut | |
use constant DOWNLOAD_FOLDER => '/Users/squeeks/Pictures/'; # Don't forget the trailing slash! | |
=head1 Installation | |
Stick it somewhere save and fix your crontab like so: | |
0 * * * * /location/of/your/safe/place/earth_iotd.pl | |
=cut | |
my @ltime = localtime(time); | |
my $date = sprintf("%04d-%02d-%02d", $ltime[5]+1900,$ltime[4]+1,$ltime[3]); | |
my $filename = DOWNLOAD_FOLDER.$date.".jpg"; | |
my $mech = WWW::Mechanize->new; | |
$mech->get('http://earthobservatory.nasa.gov/IOTD/'); | |
$mech->follow_link( text => 'more about this image' ); | |
$mech->follow_link( text => 'download large image'); | |
$mech->save_content($filename); | |
#TODO: Support other operating systems/window managers (patches welcome) | |
if($^O eq 'darwin') | |
{ | |
# Since I'm on dual identical displays, putting in the block of 'tell every desktop...' will mean | |
# the identical image is across both, instead of just the primary. YMMV. | |
my $cmd = qq[/usr/bin/osascript <<-EOF | |
set filename to POSIX file "$filename" | |
tell application "Finder" | |
tell (every desktop whose display name is "Apple Cinema Display") | |
set picture rotation to 0 | |
set picture to filename as alias | |
end tell | |
end tell | |
EOF | |
]; | |
system($cmd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment