-
Notifications
You must be signed in to change notification settings - Fork 2
/
set_wallpaper
executable file
·44 lines (33 loc) · 1.3 KB
/
set_wallpaper
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
#!/usr/bin/python
# Uses Cocoa classes via PyObjC to set a desktop wallpaper on all screens.
"""
Source: https://github.com/grahamgilbert/macscripts/blob/master/set_desktops/set_desktops.py
Inspired by Greg Neagle's work: https://gist.github.com/gregneagle/6957826
"""
from __future__ import print_function
import argparse
import sys
from AppKit import NSScreen, NSWorkspace
from Foundation import NSURL
parser = argparse.ArgumentParser(description='Sets the desktop picture on all screens')
parser.add_argument('--path', help='The path of the image')
args = vars(parser.parse_args())
if args['path']:
picture_path = args['path']
else:
print('You must supply a path for the desktop picture', file=sys.stderr)
exit(-1)
# generate a fileURL for the desktop picture
file_url = NSURL.fileURLWithPath_(picture_path)
# make image options dictionary we just make an empty one because the defaults are fine
options = {}
# get shared workspace
ws = NSWorkspace.sharedWorkspace()
# iterate over all screens
for screen in NSScreen.screens():
# tell the workspace to set the desktop picture
(result, error) = ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, options,
None)
if error:
print(error)
exit(-1)