|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# This is a Python script that outputs the path of the current |
| 4 | +# OSX wallpaper. |
| 5 | +# This is helpful when the desktop wallpaper is randomized |
| 6 | +# across a large collection of pictures and you want to |
| 7 | +# delete the current wallpaper. |
| 8 | +# |
| 9 | +# 2015.03.25 |
| 10 | +# Brandon Amos <http://github.com/bamos> |
| 11 | +# |
| 12 | +# --- Warning --- |
| 13 | +# + This approach doesn't work multiple monitors. |
| 14 | +# |
| 15 | +# --- Tested On --- |
| 16 | +# + OSX Yosemite 10.10.2 with a single monitor on a MBP. |
| 17 | +# |
| 18 | +# --- Usage --- |
| 19 | +# Ensure `db_path` and `wallpaper_dir` are correctly set below. |
| 20 | +# |
| 21 | +# Assuming `get-osx-wallpaper.py` is on your path, |
| 22 | +# check the output with the following |
| 23 | +# |
| 24 | +# $ get-osx-wallpaper.py |
| 25 | +# /Users/bamos/Pictures/wallpaper/nature/496.jpg |
| 26 | +# |
| 27 | +# Please ensure this is correct before trying to remove it! |
| 28 | +# |
| 29 | +# This can be paired with other commands such as `open` or `rm`. |
| 30 | +# Run `killall Dock` to refresh the changes after removing the file. |
| 31 | +# |
| 32 | +# $ open $(get-osx-wallpaper.py) |
| 33 | +# $ rm $(get-osx-wallpaper.py) && killall Dock |
| 34 | +# |
| 35 | +# Example alias definitions for bash and zsh are available in |
| 36 | +# https://github.com/bamos/dotfiles/blob/master/.aliases: |
| 37 | +# |
| 38 | +# alias open-wallpaper='open $(get-osx-wallpaper.py)' |
| 39 | +# alias rm-wallpaper='rm $(get-osx-wallpaper.py) && killall Dock' |
| 40 | + |
| 41 | + |
| 42 | +import sqlite3 |
| 43 | +from os.path import expanduser |
| 44 | + |
| 45 | +# db_path found from: http://superuser.com/questions/664184 |
| 46 | +db_path = expanduser("~/Library/Application Support/Dock/desktoppicture.db") |
| 47 | +wallpaper_dir = expanduser("~/Pictures/wallpaper/nature") |
| 48 | + |
| 49 | +conn = sqlite3.connect(db_path) |
| 50 | +c = conn.cursor() |
| 51 | +data_table = list(c.execute('SELECT * FROM data')) |
| 52 | + |
| 53 | +# The current wallpaper is the last element in the data table. |
| 54 | +print("{}/{}".format(wallpaper_dir,data_table[-1][0])) |
0 commit comments