## -*- 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/
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
anddays-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
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.
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
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
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))
I am looking for your ideas!
If you want to contribute to this cool project, please fork and contribute!