The following post outlines how I managed to get a wallpaper compiled out of my top 50 artists at last.fm that changes automatically every hour. To achieve that I used the last.fm cover art website, Automator and the Unix utility cron.

  1. Open Automator and start a new workflow. First thing we have to make sure is that the old wallpaper gets deleted. You wouldn’t want your harddisk fill up with wallpapers. So drag the “Find Finder Items” action from the Finder Library to the workflow and set it up as showed in the picture. (Wallpaper is a folder in my Pictures folder that holds all of my background images.)
    Find Finder Items
  2. Choose the “Move to Trash” Action from the Finder Library and drag it under the previous Action.
  3. Next we have to get the desired wallpaper from the previously mentioned page. First go there and set up the wallpaper just as you like it. Make sure the “Randomise” checkbox is checked, otherwise it wouldn’t make much sense to reload the image every hour, would it? 😉
    When you’re done setting up your image click on “Image Me” and wait for the picture to appear, then copy the address from the address bar of your browser.
    Back in Automator choose the Safari Library and drag the “Get specified URLs” Action to the workflow. Paste the just copied address into the “Address” field in the Action. (Or if you did this with Safari and got the page still open, just click the “Current Safari Page” button)
    Get Specified URLs
  4. To save the image in the right folder we need the “Download URLs” Action from the Safari Library and specify the folder we chose previously in the delete step.
    Download URLS
  5. In the following two steps of the workflow the file is renamed with date and seconds till midnight, so it has a different filename each time it gets downloaded. Otherwise OS X wouldn’t change the wallpaper even if the image changed.
    Rename
  6. The last Action is Finder’s “Set the Desktop Picture” which you just have to drag into the workflow and you’re done.
  7. Save the workflow as Application into your Applocations folder and remember the name. (I named mine “last.fm – Azath0th – Wallpaper”). Now comes the scary part – the Terminal 😉
  8. We have to set up a cronjob. In order to do that type in crontab -e and paste the following in the crontab file.
    SHELL=/bin/bash
    0 * * * * /usr/bin/open "/Applications/last.fm - Azath0th - Wallpaper.app"

    Of course you have to substitute the name of the program with yours.
    This executes the Automator workflow every hour at 0 minutes on every possible day. (0 * * * *)

That’s it!
A few words of caution though:

Be sure that your desired download folder doesn’t contain any other files that contain “coverart” in their filename or Automator will delete those as well.

When the workflow runs it forces itself into the foreground which can be a bit annoying sometimes. I’m not sure what happens if you’re in the middle of a presentation and the workflow kicks in, it might be better to deactivate it during those occasions by putting a hash caracter (#) in front of the call in the crontab file.

Enjoy it and please tell me if you’ve got any ideas to improve the whole thing.

Another entry in my virtual “braindump” category, so I don’t have to look it up somewhere else all the time.

If you want to periodically delete files in a specific directory the unix program find comes to the rescue. In my specific case I needed to delete all the movie files from a surveillance camera that where older than 30 days.

This is the crontab entry to accomplish that:
0 0 * * * /usr/bin/find /videos/ -type f -name '*.avi' -mtime +30 -exec rm {} \;
(everything in one line)

The code runs the program /usr/bin/find every day at midnight (0 0 * * *). It checks the directory called /videos for everything that is a file (-type f), has a name that ends in .avi (-name '*.avi') and is created 30 days ago or before that (-mtime +30).
The command then executes rm (remove) on all those files (-exec rm {} \;).

While searching for an easy way to do server side Spam filtering, so I don’t have to bear with all those spams when looking at my Inbox with Webmail, I found IMAP Spam begone. It’s a python script that scans your Inbox for new messages and hands them to Spamassasin to check their spam status and copies them to a pre-defined folder in your Maildir if it is found to be a spam message. Client side spam filtering is done with Apple Mail on my iBook which works very good for me. So there is a second layer of filtering in place in case something still gets through.

Although isbg.py is rather old and hasn’t been updatet in about three years it works very conveniently and tags nearly all of my Spams, moves them to my Junk folder and deletes them from my Inbox. The script is called from a cronjob and run every 10 minutes so there is a slight chance that I still find Spams in my Webmail before isbg.py is able to run and delete them.

The reason I settled for this “external” integration of Spamassasin via isbg.py is that I didn’t want to mess around with the transport rules of my MTA because of the chance to do something not all users are happy with. With IMAP Spam begone I have an individual solution that works for me without altering the way all the other people experience the mail service.

Below you’ll find the command line options I have running, for further explanations please refer to the projects homepage.

isbg.py --spaminbox INBOX.Junk --spamc --delete --nostats --expunge

Update: Since the ISBG site seems to be down currently, I’ll provide a download link for the script here.

isbg.py