Acorn + AppleScript: Adding a White Background

March 5, 2011

Say you have a lot of transparent images that you need to add a white background to. Flying Meat’s Acorn has some nice scripting bindings that are up to the task.

Not being a huge fan of AppleScript, I started out writing JSTalk inside an Automator task, but frankly I couldn’t figure out how to fill the new layer. Filling is, however, documented for AppleScript. I got an AppleScript version working, but quickly found that (at least on my system) running AppleScript inside Automator is very slow.

So I abandoned Automator and adapted that code to an AppleScript droplet. After saving it as an application from AppleScript Editor, I had a speedy app bundle that I could drop images on. Here’s the code:

on open input
	repeat with anImage in the input
		tell application "Acorn"
			open anImage as alias
			tell document 1
				duplicate layer 1
				fill with color (65535 & 65535 & 65535)
				merge visible layers
			end tell
			activate
		end tell
	end repeat
end open