Chopping up multiple-screen wallpapers

Here’s a (very) quick hack to grab an image, resize it to span all your Mac’s displays and chop it up (messily) using ImageMagick - it splits things up into quite a few more images than you might need, but the point here is that this works for me with 3 side-by-side displays, not all the same width.

#!/usr/bin/python

import AppKit,os,sys
from Quartz.CoreGraphics import *

span = 0
height = 0
crops = []

bounds = [CGDisplayBounds(screen.deviceDescription().objectForKey_('NSScreenNumber')) for screen in AppKit.NSScreen.screens()]
bounds.sort(key = lambda s: s.origin.x)

for (w,h) in [(s.size.width, s.size.height) for s in bounds]:
  span = span + w
  height = max(height,h)
  crops.append((w,h))

os.popen("convert -resize %d %s resized.png" % (span, sys.argv[1]))

offset = 0
for (w,h) in crops:
  print w, h, offset
  os.popen("convert -crop %dx%d+%d+0 resized.png %d.png" % (w, h, offset, offset))
  offset = offset + w