How many languages does it take to change a Keynote slide?
I was playing with Telekinesis on Friday, which lets you use an iPhone as a remote control for your Mac. The idea is simple: Telekinesis runs a web server on your machine, and the iPhone connects to it. It ships with a few Telekinesis Applications (or “tapps”), or you can write your own to control your own programs.
I wrote one to control Keynote presentations from your iPhone. It’s fairly simple: it shows you the current slide and the presenter’s notes for that slide, and it lets you go forward and backward through your slide deck. (No, it’s not release-quality yet, but expect it in a few days.)
So here’s the real meat of this blog post: (Warning: geeky-acronym-land ahead.)
- Being a Mac OS X app, Telekinesis’s UI is written in Objective C.
- It exposes a web server that can run PHP scripts.
- My remote application is a set of PHP scripts that sit on the Mac and run when the iPhone user launches the app.
- On the iPhone, the user makes a request to the PHP script, that generates HTML, CSS and JavaScript to format the page for the iPhone
- To capture the current slide, I use a command line program (
screencapture) inside a shell script from within PHP. - I resize the large slide for the iPhone using another shell script, and push it out to the phone as a stream of bytes, via PHP.
- To change slides, the user clicks the Next and Previous functions on the iPhone, which use AJAX (JavaScript, XML, XmlHttpRequest) to send the request to a PHP script;
- the PHP script interprets this request, and wants to use AppleScript to ask Keynote to update the current slide. But since there is no direct way to invoke AppleScript from PHP, we use the command-line tool
osascriptin a shell script to run our AppleScript. - Keynote hears the call to action from our AppleScript, and changes the slide.
So, our champion team now includes the following players: Objective C, PHP, HTML, CSS, JavaScript, Shell Script, and AppleScript: all with the single goal of changing a Keynote slide.
Has anyone changed lightbulbs with an iPhone yet?
