Random Desktop Background Flickr Mac

September 16th, 2011 by pyrat

Recently I wanted to change my desktop pic randomly and use flickr as a source. The currently working solution (a bit dirty) as it stands is as follows.

Every half an hour a cronjob runs which runs the following script.

change_desktop.sh

  #!/bin/bash
 
  utime=`date +%s`
  file="/tmp/#{$utime}.jpg"
  curl -L http://weeflickr.heroku.com/random_image > $file
 
  /path/to/change_desktop.rb $file

It makes a call to the wee flickr app which redirects to a random photo from your photostream. (Chooses a random set, then a random photo within that set.) This file is then saved to disk and is passed to a ruby script.

change_desktop.rb

  #!/usr/bin/env ruby
 
  # Author: Alastair Brunton
 
  require 'rubygems'
  require 'appscript'
 
  include Appscript
 
  file_path = ARGV[0]
 
  app("Finder").desktop_picture.set(MacTypes::FileURL.path(file_path))

This ruby script uses
rb-appscript
to link into apple script and change the mac desktop background.

Note: This has only been tested on snow leopard and the scripts are currently pretty brittle.

The random flickr photo functionality is available from wee_flickr photopicker.

You also need to delete the /tmp photos now and again so I have a little dirty cron that runs once per day.

  #!/bin/bash
 
  cd /tmp && rm *.jpg

Leave a Reply