Recently, whilst browsing Reddit, I came across an old thread on r/wallpapers showcasing a collection of 8-bit desktop wallpapers each of which displaying a beautiful landscape at a different time of day. The thread linked to the following Imgur gallery containing all of the images.
These images by themselves have little use but over the next few years several contributors had grouped together, using these wallpapers, to produce a live wallpaper for android, an integration with Windows and OSX, and a web implementation. Yet the Linux community were not getting much love from the project.
There are a few scripts kicking around on Github allowing users to manually set up a live version of the wallpaper but these all seem to use fixed time intervals to determine when to change the wallpaper and so in the summer and winter when the time the sun is up is far from the average value, the wallpaper is completely asynchronous to real life. What I wished to do was to set up an implementation for Linux which would use local sunrise and sunset times to adjust when the wallpaper changes to result in an experience that perfectly matches up with the real world.
I used data from the UK Hydrographic Office, a website offering free astronomical data for anybody to use. Using this site you can generate a text file containing the sunrise and sunset times for any location in the United Kingdom (with daylight savings already accounted for). I retrieved this data for the entirety of 2018. If you wanted complete accuracy this would need to be updated each year but with the annual difference of the sunrise/set times being in the handfuls of minutes, I don’t think this is necessary.
This data comes in a very messy format and so I had to perform some cleaning with R:
1 | # required libraries |
Cleaning this data is much easier in R than Python, yet to keep this blog post self-contained for anyone familiar with just the basic use of Python, I have packaged this code up into a Shiny web app which can be viewed here. Providing you collect the data from the source above using the same settings, you will be able to upload the returned text file to this web app and it will automatically clean the data for you and provide you with a CSV file to download.
Once your data is clean you can start setting up the wallpaper. You will first need Python 3 installed on your computer. You can then create a folder somewhere in your file system to contain the files relevant to this project. In this folder, you will need to download the images from the Imgur link and add the cleaned CSV file containing the sunset and sunrise times. You then need to copy any one of the wallpapers and rename it to current.png
. The choice of wallpaper to copy makes no difference as it will be overridden when the wallpaper is updated. Next you need to create a Python script in this folder containing the following code with the blanks filled in:
1 | #!/usr/bin/env python |
The last step is to to use cron, a Linux utility for scheduling jobs to run. To edit the cron tab(le) for your user simply open up the Unix terminal and enter
1 | crontab -e |
This will open the cron tab(le) and you can enter the following two lines, replacing the place-holders with the relevant paths, at the bottom of the editor
1 | */5 * * * * PATH_TO_PYTHON_INSTALLATION PATH_TO_WALLPAPER_CHANGING_SCRIPT |
Don’t forget to leave a new line after these new entries else they will fail to interpretted. If you are unsure of the location of your Python installation, running which python
in the terminal should give you the required path. The first line is used to rerun the wallpaper-updating script every 5 minutes and the second, unsurprisingly, runs it whenever the computer reboots.
If all has gone to plan, you should now have your own sun-tracking, live, 8-bit desktop wallpaper.