moltenform
Home
Previous: MIDI To Wav
Previous: MIDI To Wav
UI Automation
UI Automation
Next: Maurader's
Next: Maurader's

Tutorials



For the past few weeks I have been working on a project for Windows automation. The result is powerful JavaScript libraries for Win32 automation.

Look at this!
Process.open('notepad.exe')
Mouse.move(1,1);
Time.sleep(500);
Keyboard.send('hello!')

LnzScript is JavaScript (run locally, not in a web browser) with libraries for simulating keystrokes, mouse movements, working with files, and a lot more.

One cool aspect of the project: documentation is written inline with the C++ code. Then, a Python script creates an xml file from this documentation. This same xml file is used for reading by C++, C#, and even rendering to the browser! I wrote an xsl transform that renders the documentation, so that it can be seen in a browser. If you look at the source, you'll notice that it is xml.

AutoIt exists and is good at what it does. However, its syntax and minimal data structures will not do for non-trivial programs. More of my rational is given in the documentation.

The code editor is a custom build of Scite. I've added autocomplete and tooltips to make it faster to write scripts.

LnzScript 0.4 Update

from a blog post in 2010, halfhourhacks 2010-08-lnzscript-04.html

The LnzScript 0.4 release is here! This scripting tool can automate repetitve tasks in Windows, work with files and folders, and easily perform text manipulation.

The editor makes it easy to write quick one-off scripts. Standard output appears in a pane to the right. Let's say you have some text that you want shuffled randomly. If one were to write a Python script, you'd have to save the text in a temporary file, or load some library to access the Windows clipboard. With LnzScript, the clipboard is directly accessible without importing anything. One could just write Clipboard.set(Math.shuffleArray(Clipboard.get().split('\r\n'))) Furthermore, the LnzScript Editor can run a script before it has even been saved to a file, a unique feature, so you can run a script immediately.

LnzScript 0.4 includes more methods for working with files. File.dirListFiles(@'c:\myfolder', '*.txt','size') returns all of the text files in the directory, sorted by size. File.copyMany can copy full directories. File.createShortcut and File.getShortcutTarget can work with shortcuts. The Rename.renameFn will call a function you provide to rename files. To rename .jpeg to .jpg, say, all you need to do is:

File.cd(@'c:\myfolder');
Rename.rename('.jpeg','.jpg');

Rename.renamePreview can be used to see the results before renaming anything.

And, it's still good at automating tasks. I used it to access Webmail (for which there was not a 'remember me' option); much faster than typing in the fields every time.

The installer associates script files so that you can run them by double-clicking. Just by using argv in a script, you can now drag and drop a file into the script and it will run with that argument in argv[1], a 'droplet.' And you can use Clavier+ to assign scripts to a keyboard shortcut that works from any program.

Why JavaScript? I find it to be much cleaner than Basic-derived semi-languages. Lambdas and the good parts can be very useful. I've added @'string' literals to the language, that can contain single backslashes, so that one can type @'c:\foo' instead of 'c:\\foo'. There are other additions like include(), alert(), print(), and argv.

LnzScript is ahead of its time :), when I first wrote LnzScript, it wasn't very common for JavaScript to be used outside of the browser, but this is everywhere now.

An example using JavaScript's closures to rename files in the pattern 00, 01, 02, and so on, by last modification time:
include('<std>')
File.cd(@'C:\folder')
var i = 0;
function renameNumbered(s)
{
  i++;
  return (i < 10) ? ('0' + i + s) : (i + s);
}

Rename.renameFn(renameNumbered, 'time') // see also: renameFnPreview to preview the results before making changes

LnzScript lets you automate Windows with JavaScript.

LnzScript demo screenshot

You can script macros for frequently performed actions, write quick one-off scripts in the editor, and write tests for your software's UI.

LnzScript has 180+ available functions, documented and separated into namespaces, and comes with a full editor + autocompletion. It can simulate mouse/keyboard actions and also send input to specific UI controls by id.

Back