Created
February 4, 2016 14:03
-
-
Save clburlison/6a46bd9bdb6ad7895d99 to your computer and use it in GitHub Desktop.
Outset Desktop Set Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
'''Uses Cocoa classes via PyObjC to set a desktop picture on all screens. | |
Tested on Mountain Lion and Mavericks. Inspired by Greg Neagle's work: https://gist.github.com/gregneagle/6957826 | |
See: | |
https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html | |
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html | |
https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSScreen_Class/Reference/Reference.html | |
''' | |
from AppKit import NSWorkspace, NSScreen | |
from Foundation import NSURL | |
import argparse | |
import sys | |
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 >> sys.stderr, 'You must supply a path for the desktop picture' | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script is designed to run at user login and will set the Desktop Picture. | |
# | |
/usr/bin/python "/usr/local/bin/set_desktops.py" --path "/Library/Desktop Pictures/Solid Colors/Solid Gray Pro Ultra Dark.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The wonderful @grahamgilbert created the set_desktop.py script. https://github.com/grahamgilbert/automate_psu_2014/tree/master/set_desktops