]> code.delx.au - bg-scripts/commitdiff
Fixed a bug with dual monitors under OSX where WallChanger could not update a monitor...
authorGreg Darke <greg@tsukasa.net.au>
Sat, 19 Apr 2008 04:25:28 +0000 (14:25 +1000)
committerGreg Darke <greg@tsukasa.net.au>
Sat, 19 Apr 2008 04:25:28 +0000 (14:25 +1000)
  * Added a conditional runtime dependency on Foundation (the python objective C bindings)

lib/WallChanger.py

index 147518bc468d002ccde58b120737c0c0074b063c..fbedb0ee1a7b87a8d193e44a72e9231d86559a75 100644 (file)
@@ -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]