class __OSXChanger(__BaseChanger):
_ConvertedWallpaperLocation = '/tmp/wallpapers/'
+ _DesktopPlistLocation = os.path.expanduser('~/Library/Preferences/com.apple.desktop.plist')
+
def _removeOldImageCache(self):
"""Cleans up any old temp images"""
if not os.path.isdir(self._ConvertedWallpaperLocation):
debug("""Convert command: '"%s"'""" % '" "'.join(cmd), DEBUG_LEVEL_DEBUG)
return output_name, subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+ def _fixDesktopPList(self):
+ """Removes the entry in the desktop plist file that specifies the wallpaper for each monitor"""
+ try:
+ import Foundation
+ desktopPList = Foundation.NSMutableDictionary.dictionaryWithContentsOfFile_(self._DesktopPlistLocation)
+ # Remove all but the 'default' entry
+ for k in desktopPList['Background'].keys():
+ if k == 'default':
+ continue
+ desktopPList['Background'].removeObjectForKey_(k)
+ # Store the plist again (Make sure we write it out atomically -- Don't want to break finder)
+ desktopPList.writeToFile_atomically_(self._DesktopPlistLocation, True)
+ except ImportError:
+ debug('Could not import the Foundation module, you may have problems with dual screens', DEBUG_LEVEL_MEDIUM)
+
def changeTo(self, file):
output_name, ret = self._convertImageFormat(file)
if ret: # Since 0 indicates success
debug("Convert failed %s" % ret)
return False
+ self._fixDesktopPList()
cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % output_name
debug(cmd, DEBUG_LEVEL_DEBUG)
return not commands.getstatusoutput(cmd)[0]