iNMR icon

Setting Up iNMR to Run the Scripts

The console works like a command line where you can type commands, either built-in or created by yourself. You can also paste an whole script (a sequence of commands, statements and expressions: a computer program) and execute it. It's more efficient, however, if you create shortcuts for these scripts and save them on disk. iNMR can create shortcuts automatically, if you tell it where your scripts are stored.

The scripts are interpreted, which means that there's no difference between a script and a sequence of typed commands. iNMR can be programmed in Lua and in Apple Script. The console, however, only understands Lua, thanks to the embedded interpreter. The Lua language and the interpreter have been written and copyrighted by Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes (PUC-Rio, Rio de Janeiro, Brazil). Lua comes with its rich library of functions to manipulate numbers and strings. It's not necessary to learn the language to use a command or a script.

How to set up your computer:

Step 1

Create a folder where to store all your scripts. They can be organized into subfolders.

Step 2

Choose iNMR > Preferences. Select the first panel of the dialog.

Step 3

Click the button choose on the right. A standard Choose File dialog appears.

Step 4

Select the folder you have created at step 1. The path appears into the Preferences dialog.

The following steps are optional:

Step 5

You can define from 0 to 8 shortcut buttons that will appear into the console. The name of a button will the same as the name of the corresponding script, without the extension. Write the list of shortcuts, at the bottom of the preferences dialog, separated by spaces. If the script resides into a subfolder, prepend the name of the subfolder and a slash, ex.: subfolder/name.

Step 6

To define your own functions, to initialize some variables and to have some commands performed every time you open the console, write the necessary code into a lua file called Lua.init and place it at the top level of the folder. This file can be as long and complex as you need.

Step 7

If you wish to write scripts of your own, we suggest using external editors like Notepad++ or EditPad Lite on Windows, TextWrangler or Smultron on the Mac.

Step 8

To learn the Lua language, there's nothing better than the word of its creator.

iNMR populates the script menu, at launch time, with all the files that end with the .lua extension and reside into the designated folder. Subfolders are listed as submenus. If you add a new file into the folder and iNMR is already running, the name can't appear into the menu. The new shortcut buttons, instead, appear the next time you open the console (no need to quit the program).
To run a script from the console, without a shortcut, type:
run “path/to/the/script”
(the base path is the scripts folder; omit the extension) or:
dofile “/absolute/path/to/the/script.lua”

Apple Script (Mac-only)

The Lua console can be controlled by an Apple Script. You have two basic Apple Script commands: “dofile” to call an existing Lua script and “Lua” to pass a Lua statement directly. The console output is echoed into the Apple Script Editor.
To specify a file, either pass the absolute path with the extension or the path relative to the scripts folder, without extension.
To get the final result from the console 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. To test the mechanism, run the following code from inside the AppleScript editor:


-- the following examples show how to communicate between an AppleScript script and iNMR
tell application "iNMR"
	
	-- setting a Lua variable from outside
	setLuaNumber "x" value 2
	setLuaString "name" value "Joe"
	
	-- executing Lua statements	
	Lua "sum = x + x"
	Lua "print('x + x = '..sum)"
	Lua "print( name )"
	
	-- getting values from iNMR	
	set aNumber to getLuaNumber "sum"
	
	-- showing text into iNMR
	Lua "print 'these words comes through Lua...'"
	
end tell
display dialog aNumber buttons {"Cancel", "Ok"}

Related Topics

The Console: Command Line and Script Editor

Starting with Lua

 

Web Links

Customize your Lua Environment

Apple Scripts: the Lua Bridge

Web Library of iNMR scripts

Lua built-in functions (official manual)