Skip to content

Sets the desktop backgrounds of OS X 10.5 according to photographs which are from a similar season

License

Notifications You must be signed in to change notification settings

novoid/set_desktop_background_according_to_season

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

## -*- mode: org; coding: utf-8 -*- ## Time-stamp: <2014-08-29 16:28:55 vk> ## This file is best viewed with GNU Emacs Org-mode: http://orgmode.org/

set_desktop_background_according_to_season.py

This Python script sets your desktop background image according to the current season.

DISCLAINER: This is a works-for-me-solution which is adopted to my work flows and my computer. It works on a Mac OS X 10.5 with Python version 2.7 (from MacPorts) and some tools installed form MacPorts. Sorry, you have to go through the whole script in order to modify it that it meets your situation.

What it does:

  • get system idle time
    • using shell script with ioreg
  • if idle time is less than IDLE_TIME_BORDER minutes continue (else exit)
  • re-generate FILE_WITH_IMAGEFILES if it is older than REGENERATE_FILE_WITH_IMAGEFILES_NOT_WITHIN hours
  • read-in FILE_WITH_IMAGEFILES from LIST_OF_PATHS_TO_QUERY and parse for ISO timestamps in filenames
  • randomly choose a file which has a day (ignoring year) that is within days-before and days-after (parameters) of today.
  • set this file as new desktop background

Source: https://github.com/novoid/set_desktop_background_according_to_season

  • target group: Users of OS X who want to get more control over the selection of the desktop background images used
  • skills necessary:
    • create scheduled execution of commands (LaunchD)
    • modifying settings in a Python script file

Why

Let’s face it: This is nothing most people spend a thought on. I did it because I can and it was fun writing it :-)

I’ve had my OS X configured to switch desktop backgrounds every 15 minutes. The images I chose from was a collection of photographs I took with special tags in their file name: “(desktoppicture)” or “(dp)” or “specialL”.

This way, I get a nice slide show on cool moments I took a photo.

Imagine a hot summer day and imagine that you get christmas photographs as background images. Not quite matching in my opinion.

How about desktop backgrounds that match the current season?

My photographs contain a time stamp: “2003-09-09T14.58 green hills and blue sky - very nice (desktoppicture).jpg”

Please do read this blog article if you want to know more on how I manage my digital photographs using very simple things.

It is very easy to match seasons by looking for file name whose time stamp is similar to the current season (+/- one month if you want).

So this is it.

Periodically running this script

On my OS X 10.5 there is no crond, unfortunately. Instead, I have to use LaunchD.

create a file like “~/Library/LaunchAgents/switchdesktopbackground.plist”

<?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>switchdesktopbackground.plist</string>
        <key>UserName</key>
        <string>vk</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/vk/bin/set_desktop_background_according_to_season.py</string>
                <string>--days-after 10</string>
                <string>--days-before 30</string>
                <string>--quiet</string>
        </array>
        <key>StartInterval</key>
        <integer>937</integer>
</dict>
</plist>

Append the script to the running LaunchD server using:

launchctl load ~/Library/LaunchAgents/switchdesktopbackground.plist

After a re-boot, the agent should be started automatically. Although on my system, this does not work each time :-O

How to open the current desktop image

Sometimes, it is quite handy to open the current desktop image shown in your favorite image viewer.

You can achieve this easily by using the “–openscript=FILE” feature:

set_desktop_background_according_to_season.py --openscript=~/Desktop/open-background.sh -a 10 -b 30

To display the current desktop image, use the following command:

sh ~/Desktop/open-background.sh

Using appscript

I had to install appscript using:

cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
sudo ./easy_install appscript

You can check the basic appscript functionality to set desktop backgrounds with:

from appscript import *

f = '/Users/username/images/2012-02-18T11.17.52_img_2153.jpg'
se = app('System Events')
desktops = se.desktops.display_name.get()
for d in desktops:
    desk = se.desktops[its.display_name == d]
    desk.picture.set(mactypes.File(f))

Contribute!

I am looking for your ideas!

If you want to contribute to this cool project, please fork and contribute!

Local Variables

About

Sets the desktop backgrounds of OS X 10.5 according to photographs which are from a similar season

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages