AppleScripting HTML for SWFs
Posted on December 6th, 2006
On the heels of my recent review of a book on AppleScript comes a small utility I created to automate SWF publishing.
Let's say you've just finished working on your latest masterpiece. Now you need a companion HTML page to go along with it. Out of habit, you might reach for the HTML file that Flash usually creates for you automatically. After a little bit of fiddling with the HTML, you'll probably be all set. Or will you?
From a programming standpoint, no. Flash's default HTML is enough to get your SWF file to display properly in a browser, but it's long-winded and repetitive for esoteric reasons. There are better approaches-- I particularly like SWFObject because it takes care of displaying the movie as well as doing version detection and also copes with recent changes to Internet Explorer related to the Eolas patent dispute. From a presentation standpoint, meanwhile, the default page is pretty plain. It could look much more professional if you added something as simple as a header and footer, or at the very least centered the movie horizontally.
None of this stuff is particularly interesting when you've just finished working on Flash movie. You're done, or at least you want to be. The rest should just be minor details. So how can we automate this last mile into something that you don't even need to think about?
SWF Templater is an AppleScript droplet and web service meant to do just that. The AppleScript accepts any number of SWF files that have been dropped on it and passes them to a PHP script (more specifically, it invokes curl via the "do shell script command", and curl performs an HTTP post to the remote script). The PHP script figures out the width and height of each movie, then creates an HTML page from a standard template. It's similar to the process that Flash goes through when you publish a movie-- by doing the templating remotely, though, we can have more control over what the templates look like and be less bothered by having to keep track of SWF files and HTML files.