Giter Club home page Giter Club logo

set_desktop_background_according_to_season's Introduction

## -*- 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

set_desktop_background_according_to_season's People

Contributors

novoid avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.