MacOS – Change background image with Time

graphicsmacossettings

I created 288 different earth renders depending on sun position (one for every 5 earth minutes) based on this file from blendswap. It the image sequence starts at noon and ends at noon. I would like to set at each time of day the correct image as background image on OS X (eg at 12.00 it should be image No 1 at 18:00 it should be image No 72 ). How could I do that.

(The Original Idea was to use the "change background image every 5 minutes" setting in OS X background settings, but it only changes the picture if the computer is awake. Therefore the sequence would be out of sync every time I shut down the computer

btw I uploaded the Files

https://dl.dropbox.com/u/19023009/Blender/background.zip

They are at full Retina resolution at 650MB. + blendfile + license.

Best Answer

Thank you for your input

So finally I managed to do it (at least I think so)

I embedded an Applescript to change the background in a shell script which I added it to launchd.

This is what it looks like:

Script "scriptly.sh"

#!/bin/bash
osascript -e '
set myhour to get the (hours of (current date))
set myminutes to get the (minutes of (current date))
set mypicturenumber to (myhour - 12) * 12 + myminutes / 5 as integer
if mypicturenumber < 0 then
    set mypicturenumber to (288 + mypicturenumber)
end if
set picnumber to 0
if mypicturenumber > 99 then
    set picnumber to "0" & mypicturenumber
end if

if (99 ≥ mypicturenumber) = (9 < mypicturenumber) then
    set picnumber to "00" & mypicturenumber
end if
if 9 ≥ mypicturenumber then
    set picnumber to "000" & mypicturenumber
end if
tell application "Finder"
    set desktop picture to {"Macintosh HD:users:USERNAME:Individualfile:backgrounds:earth:earth24h" & picnumber & ".png"} as alias
end tell
'

launchd file "com.individual.Background.plist"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.individual.Background</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>/Users/USERNAME/Individualfile/scriptly.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
    <key>UserName</key>
    <string>USERNAME</string>
</dict>
</plist>

command to put it in action

launchctl load /Users/USERNAME/Individualfile/com.individual.Background.plist

EDIT:

The last command is there to load the script directly, however It will not be executed on startup. To do That you have to copy the file

com.individual.Background.plist

to the ~/Libary/LaunchAgents/ folder.