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