iNMR icon

  the Console window

The console window gives you two things:

The latter thing comprehends the former, of course. The interpreter contains code written and copyrighted by Roberto Ierusalimschy (PUC-Rio, Rio de Janeiro, Brazil), Luiz Henrique de Figueiredo and Waldemar Celes. Lua comes with its library of functions to manipulate number and strings. With it you can write complex programs but you can also evaluate simple statements, like:

print( 2 + 2 )
print( math.sin(1) ) -- the sine of 1
print(math.sin( 30 * math.pi/180)) -- the sine of 30°

If you have already seen a math expression in your life (who hasn't?) Lua is immensely simpler than AppleScript.

Although you can load a Lua program from anywhere on your hard disc with the command dofile(), the preferred solution is to gather your scripts into a single folder (which can be optionally organized into subfolders). In the preferences dialog, you can fill two fields. The first one points to the folder. The second one contains the names and sub-paths leading to the scripts you'll be using the most (your favorites). Insert the filenames (without the .lua extension) separated by a space. Both fields are optional. Although it's not absolutely necessary, add the extension .lua to all your scripts. At the launch iNMR will create a special menu with all your .lua scripts and you can launch them directly from the menu-bar. If you add/remove a file when iNMR is already running, the menu will not be updated. The bottom of the console will contain from zero to 8 buttons named after your favorite scripts. You can launch a script either pressing a button or selecting it from the menu.

You can save your console session (limited to the last 20 statements) inside the active spectrum. Press the disc-button. After you have saved it, you can reload the scrit with the folder-button. If the script already exists, the disc button, instead of over-writing it, opens the existing file with TextEdit (or the default editor of your Darwin environment). It's good practice to start your processing scripts with “reload()”: in this way you are sure to start from the FID every time.

To consult the list of commands defined by iNMR, press the “?” (help) button. The web contains the list of the other Lua built-in functions.

“For All Documents”

With this option, each single Lua command is executed for all the open documents before the program advances to the next statement. Commands that return a value, however, always return a single value (normally extracted from the foremost document). There's a command (next_window) to switch to the next window. You should use it, instead of the check button, to effectively loop over a set of documents. In summary: use the option “For All Documents” when you are using the console as a command line. Use next_window() when writing a program.


Apple Script

The Lua console can be optionally controlled by Apple Script. The final effect is that you can run Lua code inside Apple's Script Editor. You have two basic commands: “dofile” to call an existing Lua script and “Lua” to pass a Lua statement directly (for example, to set the value of a variable) and reporting the output directly inside the Script Editor window. To get the last console output you can also use “get message”, while “set message to...” performs the inverse task (useful for debugging your scripts, for example). You can also set and get the value of the option “for all documents”, with the syntax: “set forall to true”, etc...
With Apple Script you can include iNMR operations into a flow that involves more applications.

See also

Starting with Lua

Console Commands

Lua built-in functions on the web

Keyboard: what you can do with it

Metabolomic Toolbox