Matt Brock's SysAdmin+ Blog

The Writings of a Freelance Infrastructure Consultant

How to use Flickr favourites as your screensaver in Mountain Lion —

Mountain Lion is an improvement on Lion, which I had mixed feelings about when it was released. Unfortunately, however, Apple seems to have decided that RSS is a dead technology, and consequently the handy RSS screensavers have been removed, which means there’s no simple way of creating a screensaver out of one’s Flickr favourites.

Having come up with an effective solution for how to get Flickr favourites as a screensaver in Mountain Lion, I thought I’d share the method for the benefit of those who are not so used to fiddling with the deeper technological aspects of their Mac. I’ve gone into quite a lot of detail for those who are less technically-minded, but those of a more technical bent can just skip ahead accordingly.

Set up the RSS feed

Flickr does its best to make this process less than straightforward by not providing large versions of images in its RSS feeds, so we need to use a Yahoo! pipe to generate the RSS feed.

Firstly, visit your “Favorites” page on Flickr. To make it easier to see what you’re doing, change the “View” to “Square thumbnails”. You should then see something like this (only for your own favourites rather than mine, of course). At the bottom of the page you will see a “Subscribe to your favorites” link. Right-click (or Ctrl-click, or two-finger click) on that, and choose the option to “Copy Link” (or whatever the equivalent is in your browser if you’re not using Safari).

Next, visit the very handy Flickr Feed Image Re-sizer. Where it says “Flickr photo RSS feed”, paste in the link you just copied from your “Favorites” page. Make sure it has “Large” in the “Size” box, then click the “Run Pipe” button. This should produce something in the pane below which looks like a slideshow of your Flickr favourites. Right-click (or Ctrl-click, or two-finger click) on the “Get as RSS” link, and choose the option to “Copy Link” (or whatever the equivalent is in your browser if you’re not using Safari). Paste this link into a temporary place so you can come back to it shortly – a temporary document in TextEdit is as good a place as any.

Create the folders you need on your Mac

From here on it is necessary to venture into the dark underbelly of OS X via the use of the Terminal. So, launch the Terminal app using your preferred launch method. If you’re not sure how to do this, type ⌘-Space to bring up Spotlight, then type “terminal”, then choose “Terminal” in “Applications”, then hit Enter to launch it.

Then we make sure we have the folders we will need, so type (or copy and paste) the following line into the Terminal:

mkdir -p ~/Pictures/Flickr_faves ~/Library/Scripts ~/Library/LaunchAgents

Create the script to download the images

The first thing we need to do next is determine what your short username is. On OS X, every user has a long username and a short username. For example, my long username might be “Matt Brock” and my short username might be “mattbrock”. If you already know for sure what your short username is then that’s great. If not, then just type the following into the Terminal and it will tell you:

echo $USER

Make a note of this somewhere if you’re not sure you can remember it.

Next we create the script which will get the latest favourites and clear out old ones, so type:

nano ~/Library/Scripts/get_Flickr_faves.sh

This will bring you into a text editor. Paste in the following text:

#!/bin/bash

if ! cd ~/Pictures/Flickr_faves ; then
  logger "get_Flickr_faves: failed to cd to ~/Pictures/Flickr_faves; exiting"
  exit 1
fi

if ! curl -s "http://pipes.yahoo.com/" > /dev/null 2>&1 ; then
  logger "get_Flickr_faves: couldn't connect to Yahoo Pipes; exiting"
  exit 1
fi

curl -s "URL" | grep "media:content" | awk -F '"' '{print $6}' | \
  xargs -L1 curl -s -O

find . -mtime +1 -exec rm -f {} +

NO_IMAGES=$(ls | wc -l | sed "s/ //g")

logger "get_Flickr_faves: completed; $NO_IMAGES images"

Then use the arrow keys on your keyboard to move around. You need to replace URL with the long RSS feed address which you pasted into a temporary location earlier – you can use regular copy and paste, plus the arrow keys and the delete key to do all this. Make sure you don’t change anything else, and make sure you keep the quotation marks around the RSS feed address.

Once that’s done, type Ctrl-O, then Enter to confirm, to save the changes. Then type Ctrl-X to exit the text editor. Then type the following to give your new script permission to run:

chmod 755 ~/Library/Scripts/get_Flickr_faves.sh

You can now run the script once to download your Flickr favourites:

~/Library/Scripts/get_Flickr_faves.sh

Hopefully that won’t produce any errors, and if you go into Finder to look in the “Flickr_faves” folder in your Pictures folder, you should see local copies of your Flickr favourites in there.

Tell your Mac to update the images once per day

Next we need to tell your Mac to run the script we just created once a day in order to update the images from your favourites on Flickr. So, run the following command:

nano ~/Library/LaunchAgents/uk.co.mattbrock.Flickr_faves.plist

This will again bring you into a text editor. This time, paste in the following:

<?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>Label</key>
  <string>get_Flickr_faves</string>
  <key>Program</key>
  <string>/Users/USERNAME/Library/Scripts/get_Flickr_faves.sh</string>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Minute</key>
    <integer>15</integer>
    <key>Hour</key>
    <integer>15</integer>
  </dict>
  <key>Debug</key>
  <true/>
  <key>AbandonProcessGroup</key>
  <true/>
</dict>
</plist>

N.B. This assumes that your home directory is in /Users. If you’ve moved your home directory then you’ll need to alter the Program string to point to the alternative location instead of /Users/USERNAME. If you don’t know what this means then ignore it because it almost certainly doesn’t apply to you.

Replace USERNAME with your short username, then type Ctrl-O, Enter, then Ctrl-X to save and exit the editor. This is a set of instructions to tell your Mac to run the script we created earlier once a day in order to make sure your Flickr favourites are kept up to date locally. In order to get your Mac to read and act upon these instructions, we need to run the following:

launchctl load ~/Library/LaunchAgents/uk.co.mattbrock.Flickr_faves.plist

Hopefully that won’t produce any errors. We’re almost there now.

Configure the screensaver on your Mac

So all we need to do now is point the slideshow screensaver at the folder we created earlier to store the images from your Flickr favourites. Go into Desktop & Screen Saver in your System Preferences, then choose one of the Slideshows, then under “Source” choose “Choose Folder…”, then navigate to the Flickr_faves folder in your Pictures folder. It’s up to you whether you choose “Shuffle slide order” – personally I prefer to have that on, as I like a bit of randomness. Then choose a time under “Start after” to determine how soon you’d like the screensaver to start up. Alternatively/additionally, you can click Hot Corners and choose a hot corner to trigger your new screensaver on demand.

And that should be it! If all has gone well, your screensaver will now show you all your latest Flickr favourites. Enjoy.

Troubleshooting

You should be able to see the results of this automated script by launching Terminal and then typing:

grep get_Flickr_faves /var/log/system.log

This should show you the times when the task has run and what happened when it tried. When it’s been successful you will see something like the following:

Sep  4 15:17:56 mymac me[27308]: get_Flickr_faves: completed; 36 images

Edit: Judging by the comments I’ve received, some people are trying this and finding that no images get downloaded. If that happens to you then drop me an email and I’ll troubleshoot it with you to find out what the problem is. It certainly works for me so should work fine for others too.


Categorised as: Photography | Technology


6 Comments

  1. Valentin says:

    thanks! unfortunately didn’t work for me. .

  2. James says:

    Didn’t work for me either. Followed the instructions closely and then went through the steps again to verify. When I run grep get_Flickr_faves /var/log/system.log I see completed but with 0 images. The pipe utility shows images there but nothing written to file.

    • Matt Brock says:

      Sorry to hear that. What happens if you go into Terminal and run this

      curl -s "URL" | grep "media:content" | awk -F '"' '{print $6}'

      replacing URL with the long web address you got from the Flickr Feed Image Re-sizer? It should output a list of addresses for images in your favourites. Try running it several times because occasionally it doesn’t respond.

  3. wolfram says:

    Hi Matt,

    this script is quite dangerous for users having moved their Home folder to a different location (which occurs quite often if one installs ML to an SSD).
    The first test run of the script deleted all my files.
    Obviously, because you create the pictures folder at

    ‘mkdir -p ~/Pictures/Flickr_faves’

    but use

    ‘cd /Users/USERNAME/Pictures/Flickr_faves’

    later on, and if these two differ, then your script does not cd anywhere and ‘rm -f’ runs from the users Home…

    Maybe you want to change your How to a little bit?

    For the sake of your peace of mind: Fortunately I had a recent backup. :-D

    Thanks for the rest of your idea, hope I get it running soon, but I thought it urgent to comment first,

    Wolfram

    • Matt Brock says:

      Sorry this caused you problems. Thanks for the feedback. I’ve made several modifications to ensure that if someone has moved their home directory (or if for any other reason it fails to cd to the correct location) then the user will not suffer the same fate that you did. Please test the modified ~/Library/Scripts/get_Flickr_faves.sh script if you can, and let me know how it goes. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>