Created
June 16, 2016 17:34
-
-
Save rderewianko/e4d65907c5a41e791635ed83dd675e85 to your computer and use it in GitHub Desktop.
Default wallpaper
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 | |
# 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 | |
try: | |
from AppKit import NSWorkspaceDesktopImageScalingKey | |
except ImportError: | |
NSWorkspaceDesktopImageScalingKey = u'NSWorkspaceDesktopImageScalingKey' | |
from AppKit import NSImageScaleProportionallyUpOrDown | |
try: | |
from AppKit import NSWorkspaceDesktopImageAllowClippingKey | |
except ImportError: | |
NSWorkspaceDesktopImageAllowClippingKey = u'NSWorkspaceDesktopImageAllowClippingKey' | |
from Foundation import NSURL | |
picture_path = "<backgroundhere>" | |
# generate a fileURL | |
file_url = NSURL.fileURLWithPath_(picture_path) | |
# make image options dictionary | |
options = { | |
NSWorkspaceDesktopImageScalingKey: NSImageScaleProportionallyUpOrDown, | |
NSWorkspaceDesktopImageAllowClippingKey: True | |
} | |
# get shared workspace | |
ws = NSWorkspace.sharedWorkspace() | |
# iterate over all screens | |
for screen in NSScreen.screens(): | |
# tell the workspace to set the desktop picture | |
# on 10.6 this returns 0 (failure) or 1 (success) | |
# on 10.8 this returns a tuple (result, error); success is (True, None) | |
result = ws.setDesktopImageURL_forScreen_options_error_( | |
file_url, screen, options, None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment