#! /usr/bin/perl -w # SS-RSS_rotate.pl # release version 1.2 # May 14, 2005 # rick@aveight.com # Rick Smith # # VERSION HISTORY: # version 1.1 bug: between 00 and 05, mismatch of RSS key occurred. # Fixed by treating $current_hour as a number, which removes any leading # zeros, resolving those mismatches. Also, changed RSS feeds hash into array # for simplicity. # version 1.0 feature: random RSS rotation. # Moved to sequential rotation of feeds in later versions. # inspired by Macosxhints.com Article: # http://www.macosxhints.com/article.php?story=20050503144058333 # 10.4: Show MacOSXHints on RSS screen saver # I DECLARE: I have no affiliation with the RSS feeds in the demonstration of this script. I am a fan of these sites, and I wrote this script to modify my own personal news gathering. It is provided AS-IS, and you should use it at your own risk. Only minimal Perl experience is required to edit the original RSS feeds. # I wrote this Perl script to rotate the RSS feeds every hour, using the plist hack hint as a basis. Currently, there are 6 feeds, and the script works best when the total number of RSS feeds divides 24 hours nicely, which insures that each feed gets an equal shot in the rotations each day. An interesting note - if the RSS Screensaver plist file is modified while the screensaver is running, the display won't change to the next feed until the screensaver is reloaded (deactivated, then reactivated). # DEPENDENCIES: # A cron task to execute this script hourly is required for full installation. # example crontab: 0 * * * * /Users/rick/cron/SS-RSS_rotate.pl # remember to set executable permissions on this script for cron user # CHANGE NEXT VARIABLE DEFINITION TO YOUR PREF FILE'S NAME my $plist_file = '/Users/rick/Library/Preferences/ByHost/RSS Visualizer.000a95e55de2.plist'; my @RSS_sites = ( # Macosxhints 'www.macosxhints.com/backend/geeklog.rdf', # BBC News 'newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml', # Slashdot 'slashdot.org/index.rss', # TheRegister 'www.theregister.co.uk/excerpts.rss', # Macworld News 'www.macworld.com/rss.xml', # Versiontracker 'www.versiontracker.com/macosx/recent.rss' ); my $current_hour = `date "+%H"`; my $num_urls = @RSS_sites; my $max_val = $num_urls - 1; while ($current_hour > $max_val) { $current_hour = $current_hour - $num_urls; } # use HOUR in math op. to strip off leading zero, if it's there - a PERL trick $current_hour = $current_hour + 1 - 1; change_RSS_feed($RSS_sites[$current_hour]); exit(); sub change_RSS_feed { my $new_feed = $_[0]; # convert plist binary into XML `plutil -convert xml1 "$plist_file"`; open (J, "$plist_file") || die $!; my @lines = ; close (J); my $line_string = ''; # Open the XML file in your favoriate editor, and locate this line: feedURL # Under that tag, you'll find the URL of the RSS feed. Change the current entry to this: foreach my $line (@lines) { if ($line =~ /(.*)<\/string>/) { $line =~ s/$1/http\:\/\/$new_feed/; } $line_string .= $line; } # Now save the file ... open (K, "> $plist_file") || die $!; print K "$line_string"; close (K); # and convert it back into binary plist format by using this command: `plutil -convert binary1 "$plist_file"`; return "SS-RSS feed updated to $new_feed"; }