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


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.
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 | # ]