It isn't often these days that a new application makes me slap myself on the side of the head and say, "Wow! Why didn't someone think of this sooner?" But that was my reaction when I heard about Fake [1], a new Web browser from Todd Ditchendorf. And after I'd recovered from stunning myself, I said, "Wow! I can't believe someone implemented this so brilliantly!"
Before you run for cover, wondering why anyone would need yet another Web browser, hear me out. Fake isn't just any Web browser, and it isn't really intended to replace your current browser. It has a special purpose, and you might use it only for that purpose. But when you need it, there's nothing else like it.
Fake is a programmable Web browser. Its goal is to make it easy for you to write a script that can drive the Web browser itself, and that can be run against the currently displayed Web page, operating on its interface. There are other ways to write such a script; for example, you could code it in JavaScript. And there are other ways to run such a script against a Web page, more or less automatically; for example, that's what Greasemonkey [2] does in Firefox [3]. But remember, I said "easy." Exploring a Web page's HTML to work out how to access an element within it through JavaScript, and then writing and maintaining the JavaScript code to do that, hardly counts as easy. Fake lets you assemble your script with a point-and-click interface.
Fake's interface is deliberately reminiscent of Apple's own Automator (see "Meet Automator [4]," 2 May 2005), where you assemble prefabricated but configurable "actions" into a "workflow," usually as a substitute for writing code in AppleScript. But Fake goes Automator one better; Apple never did give Automator any decent programmatic logic, such as loops and conditions and error handling, whereas Fake's actions include these. Basic actions include clicking a link or other element, setting values of an element or form, and submitting a form; you can also control the browser more generally, going to a given URL, opening and closing browser tabs, and so forth. Programmers can also build snippets of JavaScript, AppleScript, or Unix shell script into a workflow.
Here's an example of how easy it is to construct a basic workflow. I often want to search TidBITS for past articles I've written. I want these to be articles where I'm an author, not articles where I'm mentioned in some other way. We have an Advanced Search page with an Author field I can fill out; to get there, I must click the little gear symbol next to the search field at the upper left of our main page. Now I'll construct a workflow to go to the Advanced Search page and put "Neuburg" in the Author field.
I start with a Load URL action, pasting in our home page URL: http://www.tidbits.com/ [5]. Now I add a Click HTML Element action. This has a field where I can put in an identifier for the little gear icon. But which element is the little gear icon? I don't need to know the answer; I just Control-drag from the action to the gear icon itself, and an expression identifying it appears in that field. Finally, I add a Set Value of HTML Element action; once again I Control-drag, this time to the Author field, to set the first field of that action, and then I type "Neuburg" into the second field of that action.
So far, all I've done is drag some actions into my workflow, configure them by Control-dragging right to the elements I want to operate on, and type my name once. Not too difficult! However, I also need to provide a way of waiting until each desired page has loaded the element I'm going to operate on. No problem; I intersperse two Wait For Condition actions between the three actions I already have, copying and pasting from my existing actions the information about the element that needs to exist before proceeding. My workflow is finished!
Finally, I save my workflow as a file called "Articles By Moi." Presto, I now have a double-clickable file that goes to the advanced search page and fills in my name in the Author section, ready for me to enter additional information to search on and then perform the search. And the amazing part is that I wrote it in just a few moments, with no need to consult any manuals or learn any programming languages.
[image link] [6]
Of course, if you do know some programming languages, you can incorporate your knowledge into a workflow. Here's an example that extracts the date of publication from a TidBITS article. All of our article Web pages (such as this one) start with a little header giving the article category followed by its date (followed by some further information). To get that header into Fake, I start with a Set Variable action and (you guessed it) Control-drag from the action to that header. I also assign the action a variable name; let's call it "meta_article". So now when I run that workflow, I end up with a variable "meta_article" whose content is something like this:
Blog Post | 04 Aug 2010 | Listen | Print | Comment (27)
Now I want to extract the "04 Aug 2010" part. It turns out that JavaScript can see Fake's variables, and since JavaScript has regular expressions, it can easily extract that bit. So my second action in this workflow is a Do JavaScript action. It extracts the date from the "meta_article" variable, and returns it as the "date" variable:
var meta = window.fake.get("meta_article");
var res = meta.match(/\| (.*?) \|/);
window.fake.set("date", res[1]);
Finally, I want to move that information to the clipboard. I can do that with a simple Unix shell script, so my next action is a Run Unix Script action. Unix shell scripts can see Fake variables too, in a different way:
#!/bin/sh
echo ${date} | pbcopy
Now the date from that article is sitting on the clipboard, ready for me to paste into whatever article I'm writing. Okay, big deal, I hear you thinking: I could have just selected it and copied it. But that example can be worked into a larger workflow that copies the title and date of an article and assembles it into one of our standard references, like the one referring to my Automator article above.
Fake comes with lots of other cool features. It takes advantage of Apple's WebKit to provide element-level analysis of a Web page; select a bit of a Web page and choose Window > Web Inspector to see the same pane you see in Safari by choosing Develop > Show Web Inspector (or choose Inspect Element from the contextual menu). It enables scripts to be run, and stylesheets to be applied, against a Web page after it loads (like Greasemonkey). And it is itself scriptable, so instead of writing a workflow, you could drive Fake, using AppleScript or the equivalent, to perform a series of actions that you're defining in real time.
I imagine that Fake would be a heaven-sent boon to developers who need to automate interactions with a Web browser (for example, to test a Web application, such as the Take Control [7] ordering process). But it's so insanely easy to use - at its most basic, just drag an action into a workflow, and drag from that action to the thing on the Web page that it operates on - that I'd think it would help anyone who does any kind of repetitive browser activity where Safari's auto-filling of forms doesn't cut it. If you think Fake wouldn't be any use to you, reread the examples above and think again about your own browser life. I bet there's some Web form or repeated sequence of Web pages where Fake could condense many mouse-clicks into one for you.
As I've already said, I think Fake is a brilliant idea, brilliantly implemented. It's the culmination of years of work by its developer, who has generously given away many tools resulting from his labors along the way (such as the other specialized browsers Fluid [8] and Cruz [9], plus much of the code on which they depend), and is responsive, active, and extremely patient and helpful on a Google group [10] devoted to Fake. Fake costs a very reasonable $29.95, with a feature-limited trial version (notably, it can't save workflows) available as a 4.9 MB download, and it requires Mac OS X 10.5 or later. I recommend it.
[1]: http://fakeapp.com/
[2]: http://www.greasespot.net/
[3]: http://www.mozilla.com/firefox/firefox.html
[4]: http://db.tidbits.com/article/8089
[5]: http://www.tidbits.com/
[6]: http://db.tidbits.com/resources/2010-09/fakeInAction.png
[7]: http://www.takecontrolbooks.com/
[8]: http://fluidapp.com/
[9]: http://cruzapp.com/
[10]: http://groups.google.com/group/fakeapp