Programmatically change URLs for Opera Speed Dial links

Dec 31, '09 07:30:00AM

Contributed by: titaniumtroop

I like to keep a weather page from Wunderground on my Opera speed dial. The monthly summary page contains the information I'm seeking (moon phase and sunrise/sunset). However, the URL contains a date, and the page displays information for that date. I was changing the date manually once a month, but this method doesn't show accurate daily information. So, I wrote a perl script that changes the date every day. I use cron to run the script at midnight every day (I hate launchd; it's overly complicated).

Opera stores information about Speed Dial links in a text file located at ~/Library » Preferences » Opera Preferences » speeddial.ini. This script closes Opera and changes the date in the URL in the speeddial.ini file.

NOTE: This script uses killall to close Opera, since cron will not properly execute AppleScript. Use care on a multiuser computer.

#!/usr/bin/perl -w

use strict;

my $homedir = $ENV{ HOME };

open(SPEEDREAD, "<$homedir/Library/Preferences/Opera\ Preferences/speeddial.ini") || die "Couldn't open speeddial.ini file.\n";

my $filedump = '';

if (`ps -ax | grep "Opera"` =~ /Applications\/Opera/) {
	`killall 'Opera'`;
}

while(<SPEEDREAD>) {
	my $line = $_;
	if ($line =~ m/Url=http:\/\/www.wunderground.com\/history\/airport\/(\w+)\/\d+?\/\d+?\/\d+?\/MonthlyHistory.html/) {
		my $airport = $1;
		(my $year, my $month, my $day) = split(',',`date "+%Y,%m,%d"`);
		chomp $day;
		print "DATE:\t$year-$month-$day\n";
		$filedump .= "Url=http:\/\/www.wunderground.com\/history\/airport\/$airport/$year/$month/$day/MonthlyHistory.html\n";
	}
	else {
		$filedump .= $line;
	}
}

close(SPEEDREAD);

open(SPEEDWRITE, ">$homedir/Library/Preferences/Opera\ Preferences/speeddial.ini");
print SPEEDWRITE $filedump;
close(SPEEDWRITE);
[robg adds: I haven't tested this one.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091223093735853