Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created February 17, 2015 13:35
Show Gist options
  • Save jacobsalmela/8e878ad47c962ab119d4 to your computer and use it in GitHub Desktop.
Save jacobsalmela/8e878ad47c962ab119d4 to your computer and use it in GitHub Desktop.
Script that enforces the wallpaper on Mavericks and Yosemite
#!/usr/bin/python
# Universal enforce wallpaper script for 10.9 and up
# Based on https://gist.github.com/gregneagle/6957826#file-gistfile1-py
from AppKit import NSWorkspace, NSScreen
from Foundation import NSURL
from platform import mac_ver
from subprocess import call
from os import system
from os import getlogin
import sqlite3
# Set path here for 10.9+
picture_path = "/Library/Desktop Pictures/Custom.jpg"
u = getlogin()
if ( u == '_atsserver') or ( u == 'root'):
print "Nothing to do as " + u
v, _, _ = mac_ver()
v = float('.'.join(v.split('.')[:2]))
desktop_db = '/Users/' + u + '/Library/Application Support/Dock/desktoppicture.db'
conn = sqlite3.connect(desktop_db)
conn.text_factory = str
c = conn.cursor()
def commit_changes():
#------------------------
conn.commit()
conn.close()
def get_current_wallpaper():
#------------------------
c.execute("SELECT * from data")
for row in c.fetchall():
return row[0]
commit_changes()
if (v == 10.9) or (v == 10.10):
print str(v) + " detected..."
current = get_current_wallpaper()
if (current != '/Library/Desktop Pictures/Custom.jpg'):
print 'Incorrect wallpaper detected. Changing...'
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:
print 'Wallpaper is correct.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment