Wrote some quick logic to scrape a web page (currently Unsplash) using xPath format to find all useful (ie. high quality) images, pick a random one, save/update locally and set as my current desktop background.
- Ensure you have a Python environment setup on your machine.
- Install PhantomJS (ie.
brew install phantomjs
) and ensure it has been added to your PATH. - Run
pip install virtualenv
. - Create your virtualenv by running
virtualenv desktop-randomizer
(this path has been added to.gitignore
). - Activate virtualenv by running
source desktop-randomizer/bin/activate
. - Install frozen dependencies by running
pip install -r requirements.txt
. - Create an image file in your "Desktop Images" folder called
RandomizedImage.jpg
(this name can be changed insettings.py
). - Run
./main.py
to update Desktop image.
This script could be configured to run automatically to keep your desktop extra fresh.
OS X (Launchd):
- Remove the ".ex" at the end of
com.user-name.desktop-randomizer.plist.ex
and replace all instances of {{user-name}} with whatever you'd like (including in the file name). - Move file to
/Library/LaunchAgents
. - Ensure
<key>EnvironmentVariables</key>
and<key>ProgramArguments</key>
paths are pointing to the correct folders on your machine. - Update the
<key>StartCalendarInterval</key>
node to set when you'd like to have the script run (currently its set to daily at midnight).
Currently, Unsplash's "new" page is used to scrape random images. This can be changed to point to another site, but then all image
config props (ie. IMAGE_*
) in settings.py
must be updated for the script to scrape appropriately. Also, if Unsplash ever decides
to modify their markup then the IMAGE_XPATH_LOGIC
config prop will need to be updated, too.
This repo was built with OS X only support in mind. It wouldn't take much to support Windows (ie. change "Desktop Images" folder path), but it wasn't necessary for me at the time of implementation.