Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Forked from gregneagle/gist:6957826
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobsalmela/4622de1f5696f562e84d to your computer and use it in GitHub Desktop.
Save jacobsalmela/4622de1f5696f562e84d to your computer and use it in GitHub Desktop.
(OS X) Universal script for setting the wallpaper. Works on 10.6-10.9
#!/usr/bin/python
# Universal wallpaper script for 10.6 and up
from AppKit import NSWorkspace, NSScreen
from Foundation import NSURL
from platform import mac_ver
from subprocess import call
from os import system
# Set path here for 10.9
picture_path = "/Library/Desktop Pictures/Custom.jpg"
# http://stackoverflow.com/questions/1777344/how-to-detect-mac-os-version-using-python
v, _, _ = mac_ver()
v = float('.'.join(v.split('.')[:2]))
print v
if (v == 10.9):
print str(v) + " detected..."
file_url = NSURL.fileURLWithPath_(picture_path)
options = {}
ws = NSWorkspace.sharedWorkspace()
for screen in NSScreen.screens():
(result, error) = ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, options, None)
else:
# Set path below for 10.6-10.8
setSnowLeopardWallpaper="""wallpaper="/Library/Desktop Pictures/Custom.jpg"
echo "Non-Mavericks OS detected..."
for username in /Users/*
do
user=$(basename "${username}")
if [ ! "${user}" = "Shared" ];then
rm "$username"/Library/Preferences/com.apple.desktop.plist
/usr/libexec/PlistBuddy -c "Add Background:ImageFilePath string $wallpaper" "$username"/Library/Preferences/com.apple.desktop.plist
/usr/libexec/PlistBuddy -c "Add Background:default:ImageFilePath string $wallpaper" "$username"/Library/Preferences/com.apple.desktop.plist
else
:
fi
done
killall Dock"""
system(setSnowLeopardWallpaper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment