Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Programmatically change URLs for Opera Speed Dial links Web Browsers
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.]
    •    
  • Currently 1.79 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (14 votes cast)
 
[7,867 views]  

Programmatically change URLs for Opera Speed Dial links | 7 comments | Create New Account
Click here to return to the 'Programmatically change URLs for Opera Speed Dial links' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Talk about overly complicated!
Authored by: ttt on Dec 31, '09 09:30:54AM

Seems kinda wrong to moan about launchd and then whip out Perl to muck with Opera. It would make a lot more sense to just have a CGI redirector that works with any browser, or maybe even a bookmarklet that doesn't require anything outside the browser at all.



[ Reply to This | # ]
AppleScript Possible?
Authored by: renaultssoftware on Jan 01, '10 05:26:28AM
Do you think you could use AppleScript and the date command to do this?

[ Reply to This | # ]
A bookmarklet version
Authored by: scooby509 on Jan 01, '10 07:50:08AM
Doing this as CGI... possible, but I doubt it would be much simpler (at least in terms of setup) than the OP's code.

But a bookmarklet does sound simple, so here goes:

First, I had to figure out what URL the OP was looking at. Turns out that wunderground (the name has some interesting history) uses 4 letter airport codes, so IAD is KIAD. An example:

http://www.wunderground.com/history/airport/KIAD/2010/1/1/MonthlyHistory.html

We'll put the airport code up front to make it easy to change, and determine the date portion of the URL:


a = 'KIAD'; 
d = new Date();
location.href = 'http://wunderground.com/history/airport/' + a + '/' + 
  (1900 + d.getYear()) + '/' + d.getMonth() + '/' + d.getDate() + '/MonthlyHistory.html';

I ran it through something to crunch it into a bookmarklet online. (It also wrapped it in a function, which is useful.) The end result seems to get cut off:

javascript:(function(){a='KIAD';d=new%20Date();location.href='http://wunderground.com/history/airport/'
+a+'/'+(1900+d.getYear())+'/'+d.getMonth()+'/'+d.getDate()+'/MonthlyHistory.html';})();"

On Firefox, you could use (new Date()).toLocaleFormat("%Y/%m/%d") to get the date formatted in one shot and eliminate the function() wrapper, but that's non-standard and neither Safari nor Chrome understand it. It would look like this:

javascript:location.href='http://wunderground.com/history/airport/KIAD/'
+(new%20Date()).toLocaleFormat("%Y/%m/%d")+'/MonthlyHistory.html';
In both cases, remove the newline before you paste it into your bookmarks.

[ Reply to This | # ]
A bookmarklet version
Authored by: ttt on Jan 01, '10 12:11:16PM

You rock for going to the trouble to do that!



[ Reply to This | # ]
Programmatically change URLs for Opera Speed Dial links
Authored by: tedw on Jan 01, '10 08:50:13AM
to do this in applescript, use the following code (please test on a backed-up version or copy first - I don't have Opera, so I haven't tested this myself):
tell application "Finder"
	set isRunning to exists process "Opera"
end tell
if isRunning is true then
	tell application "Opera" to quit
	delay 5
end if
set homeDir to path to preferences folder from user domain as text
set fp to open for access (homeDir & "Opera Preferences:speeddial.ini") with write permission
set theFileContents to read fp
set theLines to paragraphs of theFileContents
set theNewLines to {}
repeat with thisLine in theLines
	if thisLine begins with "Url=http://www.wunderground.com/history/airport/" then
		set rawDate to short date string of (current date)
		set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
		-- short date string comes out as m/d/y, where you want y/m/d, so convert
		set temp to text items of rawDate
		set beginning of temp to last item of temp
		set moddedDate to (items 1 thru 3 of temp) as text
		set AppleScript's text item delimiters to tid
		set revisedLine to "Url=http://www.wunderground.com/history/airport/" & moddedDate & "/MonthlyHistory.html"
		set end of theNewLines to revisedLine
	else
		set end of theNewLines to thisLine
	end if
end repeat
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set outText to theNewLines as text
set AppleScript's text item delimiters to tid
set eof fp to 0
write outText to fp
close access fp
to run this daily via launchd, save the following text as whateveryoulike.plist and put it in ~/Library/LaunchAgents/ or /Library/LaunchAgents/, then load it via launchctl on the command line or by restarting the machine.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>Label</key>
	<string>my.Opera.speedial.munge</string>
	<key>Program</key>
	<string>osascript '/Path/to/script.scpt'</string>
	<key>StartCalendarInterval</key>
	<array>
		<dict>
			<key>Hour</key>
			<integer>0</integer>
			<key>Minute</key>
			<integer>0</integer>
		</dict>
	</array>
</dict>
</plist>
horribly complicated, I know...

[ Reply to This | # ]
Programmatically change URLs for Opera Speed Dial links
Authored by: leamanc on Jan 03, '10 08:54:51PM

Yeah, launchd may be a little bit more work up front, since you have to craft an XML file (and that's not even true if you use something like Lingon), but the flexibility of loading/unloading agents, and the added criterion for triggering your scripts other than just date and time are well worth it, IMO.



[ Reply to This | # ]
Programmatically change URLs for Opera Speed Dial links
Authored by: tedw on Jan 03, '10 09:52:30PM

like most things programming-ish, there's a trade off between compactness and accessibility. cron is more compact notation, launchd is (arguably) more accessible, but both take about the same mental overhead to get things done. I can write launchd plists in the blink of an eye, whereas it would take me ages to figure out all the fiddly little symbolic nuances of cron.



[ Reply to This | # ]