# 2009-09-23 Astronomy Picture of the Day for Mac OSX Desktop Background

Based on Harold Bakker's APOD script, I offer the following solution. I don’t keep my computer running, so I just install the following Apple Script as a login item (→ System Preferences → Accounts → Login Items):

(* Place your with timeout statement within a try... on error statement to prevent the script from
stopping when a timeout occurs. *)
try
-- Give the script a three minute timeout to prevent problems when this is run as a login item
with timeout of 180 seconds
do shell script "~/bin/apod.pl >> /var/tmp/console.log" -- append the result to the console log
end timeout
on error errMsg -- display a dialog only if an error occurs
display dialog errMsg giving up after 10
end try

You should probably create a new script using the Script Editor on your system, paste the above, and save it as an application. Remember to untick the startup screen checkbox.

You’ll notice that it runs a Perl script called /bin/apod.pl – you should create that directory, put the following Perl script in it, and make it executable. I keep both apod.app and apod.pl in the same /bin directory.

#!/usr/bin/perl

# This script will download the astronomy picture of the day and set
# it as the current desktop background.

# originally by Harold Bakker, harold@haroldbakker.com
# http://www.haroldbakker.com/

# changes by Alex Schroeder <alex@gnu.org>
# http://emacswiki.org/alex/

use strict;
use LWP::UserAgent;
use File::Temp qw/tempfile/;

my $ua = LWP::UserAgent->new; my$response = $ua->get("http://antwrp.gsfc.nasa.gov/apod/astropix.html"); if ($response->is_success
and $response->content =~ /href\="image\/([^\/]+)\/(.*?)"/) { my$url = "http://antwrp.gsfc.nasa.gov/apod/image/$1/$2";
my $filename =$2;
$response =$ua->get($url); if ($response->is_success) {
my ($fh,$tempfile) = tempfile(UNLINK=>0);
print $fh$response->content;
close $fh; open(F, "|/usr/bin/osascript") or die "Cannot run Apple Script:$!";
print F <<END;
tell application "Finder"
set pFile to POSIX file "$tempfile" as string set desktop picture to file pFile end tell END } else { die$response->status_line;
}
} else {
die \$response->status_line;
}

This should work fine as long you restart your computer about once a day. I haven’t made sure that it will try to reuse images, saving the last one in a save place, etc.

Tags:

# 2006-08-18 Exposé or Tabs

I’ve never been a big user of Apple’s Exposé (KDE alternative: Komposé). Somehow Command-Tab (Alt-Tab on Windows) has been good enough for me. On OSX there’s an additional complication, however: If you want to switch applications, use Command-Tab. But if you want to switch windows within the same application (from one Terminal window to the next, from one Chat window to the next), you need to use Command-< (at least on a SwissGermanKeyboard).

In this context, using F9 to see all the windows of all the applications and using the mouse or the arrow keys to pick the window you want seems like a good idea.

If your applications us tabbed windows, however, you loose: You will never see windows hidden behind tabs. Just like you will never see the Emacs buffers that are not shown in a window. Is this a natural turning point for people with too many tasks?

I have no solution for Emacs, where I often have several dozen buffers open (eg. half a dozen IRC channels, half a dozen source files, an EmacsShell buffer, scratch, various directories, plus sometimes calendar or calculator). But for browsers, there is a solution: You can switch tabbed browsing on or off. So now I’m trying to live without tabbed browsing and using Exposé to navigate windows. At least for a while.

Tags:

Comments on 2006-08-18 Exposé or Tabs

C-x C-b is useful, as is either iswitchb or ido. =)

SachaChua 2006-08-19 14:32 UTC