I’ve been wanting to add JavaScript execution to CurlyQ for a while and finally got around to it.

In case you’ve missed it, CurlyQ is my command-line web automation tool for fetching, parsing, and responding to web page content, designed to be used as part of a *NIX pipeline. It can grab titles, links, metadata, and more from any web page. As part of its functionality, it can also use Firefox or Chrome to save screenshots, and that’s part of what I’ve improved.

The screenshot command now accepts a --script parameter. This can be a JavaScript string, or - to read from STDIN, or a path to a file which will be read and executed before taking a screenshot. You can also now define an element ID to wait for before taking the screenshot (or executing the script) using --id ELEMENT_ID. As long as the ID is a valid element on the page, the screenshot will trigger once that element is loaded (via HTML or dynamically), with a timeout of 10 seconds. You can also define a --wait X flag in the command to wait for a specified number of seconds after executing a script before the screenshot is taken.

Further, I’ve added a new subcommand, execute, that has the same parameters as above and simply allows you to load a page in the browser and execute a script on it. I really wanted this because it’s the easiest way to automate NiftyMenu:

curlyq execute -b chrome -s "NiftyAPI.find('file/save').arrow().shoot('file-save')" file:///Users/ttscoff/Desktop/Code/niftymenu/dist/MultiMarkdown-Composer.html

That command will save a screenshot of the File->Save menu item for me, allowing me to fully automate menu screenshots for any of my apps. I can have NiftyMenu generate an up-to-date view of the app’s menu bar, with styling for the current OS, and output detailed screenshots with callouts automatically. This will be a huge timesaver when it comes to documentation.

You can update/install the latest version of CurlyQ with gem install curlyq. The improvements in this post are available as of version 0.0.12. Enjoy!