From ee6b88d0a59b3d6ab80ec855457f3851831607d6 Mon Sep 17 00:00:00 2001 From: Greg Darke Date: Sat, 19 Apr 2008 14:25:28 +1000 Subject: [PATCH] Fixed a bug with dual monitors under OSX where WallChanger could not update a monitor if it had previously changed the wallpaper with the monitor disconnected. * Added a conditional runtime dependency on Foundation (the python objective C bindings) --- lib/WallChanger.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/WallChanger.py b/lib/WallChanger.py index 147518b..fbedb0e 100644 --- a/lib/WallChanger.py +++ b/lib/WallChanger.py @@ -118,6 +118,8 @@ class __WMakerChanger(__BaseChanger): 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): @@ -136,11 +138,27 @@ class __OSXChanger(__BaseChanger): 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] -- 2.39.2