For the latest version of JMP Help, visit JMP.com/help.


Publication date: 04/28/2021

Table Scripts

You can add a new script, run a script, or get a script using JSL.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Script( "Bivariate Example", Bivariate( Y( :weight), X( :height ) ) );
dt << Get Table Variable( "Bivariate Example" );

// returns Bivariate( Y( weight ), X( height ) )

dt << Run Script( "Bivariate Example" )

The following example replaces the contents of the table script that was created by the preceding script:

dt << Set Property( "Bivariate Example", Bivariate( Y( :weight ), X( :height ), Fit Line ) ); // include Fit Line in the Bivariate Example script

Suppose you want a text representation of a data table, perhaps to e-mail to a colleague or to use as part of a script. You can obtain a script that reconstructs the information in a data table with Get Script. The following example opens Big Class.jmp and prints the data, table variables, and column properties to the log. A portion of the output is shown here:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Get Script;

New Table( "Big Class",

Add Rows( 40 ),

New Script(

["en" => "Distribution",...],

Distribution(

Continuous Distribution( Column( :weight ) ),

Nominal Distribution( Column( :age ) )

) ),

Delete Scripts deletes one or more scripts.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Delete Scripts( "Distribution" );

In JMP versions prior to 14, use Delete Property to delete a script.

Note: The Names Default to Here setting is false by default for table scripts. If a table script specifies Names Default to Here(1), this setting lasts only as long as the table script runs. After the script finishes running, the setting is reset to whatever it was before the script ran.

Options for Downloaded Data Tables that Contain Scripts

You are prompted to open or examine downloaded data tables that contain scripts. This help you prevent potentially damaging scripts from running on your computer. In the Open() command, you can control this behavior.

To open the data table and enable scripts to run:

Open( "$DOWNLOADS/file.jmp", Quarantine Action( "Allow Scripts" ) );

To open the data table and block scripts:

Open( "$DOWNLOADS/file.jmp", Quarantine Action( "Block Scripts" ) );

To display the default prompt window to open or examine the file:

Open( "$DOWNLOADS/file.jmp", Quarantine Action( "Show Dialog" ) )

To enable a Try() expression to capture the error:

Try( Open( "$DOWNLOADS/file.jmp", Quarantine Action( "Do Not Open" ) ),
Show( exception_msg ) );

If the user selects Examine, the scripts are disabled.

Notes:

The Block Scripts and Show Dialog options don’t work if the domain that you downloaded the data table from is on your Windows Internet Options Trusted sites list.

After you select Open for a quarantined data table, the data table is trusted until the next time you open JMP.

Prompting to Run a Script upon Opening a Data Table

You can prompt to open a table script named On Open or OnOpen when the data table opens. The choice is remembered each time you open the data table in the current JMP session.

To create an On Open script, perform one of the following actions:

Create the script using the Save Script > To Data Table option, double-click the script name, and change the name to On Open.

Store the script using a New Script message.

In this example, you create an OnOpen script in Big Class.jmp.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Script(
	"OnOpen", // create the script
	sortedDt = Data Table( "Big Class" ) << Sort( By( :name ), Output Table Name( "Sorted Big Class" ) ) // sort the data and put it in a new data table
);

The JMP preference called Evaluate OnOpen Scripts determines when the script runs. By default, the user is prompted to run the script. You can set the preference to always run the On Open script or to prevent it from running:

Preference( Evaluate OnOpen Scripts( "always" ) );
Preference( Evaluate OnOpen Scripts( "never" ) );
Preference( Evaluate OnOpen Scripts( "prompt" ) ); // default setting

On Open scripts that execute other programs are never run. As a safety precaution, you might consider suppressing automatic execution when opening data tables that you receive from others.

Notes:

If the OnOpen script is in a downloaded data table, you must specify Quarantine Action( "Allow Scripts" ) in the Open() expression to run the OnOpen script automatically. See Options for Downloaded Data Tables that Contain Scripts.

When you create a new data table in a script and include the On Open() function, On Open() is called after the data table is created.

Some operations in an OnOpen script are considered unsafe, such as saving the current data table. Run an external script to save that table instead of opening a table to run the OnOpen script.

Work with Groups of Table Scripts

Suppose that you want to put related table scripts in a group to save room in the list of data table scripts. Use Group Scripts, specify the group name, and then specify the script names to put in the group.

dt = Open( "$SAMPLE_DATA/San Francisco Crime.jmp" );
dt << Group Scripts(
	"Maps",
	{"Bubble Plot Street Map", "Graph Builder Street Map: Traffic Incidents",
	"Graph Builder Street Map Zoomed"}
);
dt << Group Scripts(
	"Tabulate",
	{"Tabulate: Category and Description", "Tabulate: Category, Summary, Percentage",
	"Tabulate: Category and Resolution", "Tabulate: Resolution and Description"}
);

Move a Script Group

Move Script Group rearranges the table script groups using the to first, to last, after(script), and after(group) arguments:

dt << Move Script Group( "Tabulate", after( "Maps" ) );
dt << Move Script Group( "Tabulate", to last);

Get Groups and Group Names

To get the list of table scripts in the group, use Get Script Group. Then you can perform an operation such as running a script in the group.

tb = dt << Get Script Group( "Tabulate" );
dt << Run Script( tb[2] ); // runs the second script in the Tabulate group

Get Script Groups Names returns the group names in a list:

gn = dt << Get Script Groups Names; // returns {"Maps", "Tabulate"}
 
// move the Maps group to the end of the table scripts
dt << Move Script Group(gn[1], to last);

Select a Script Group

Select Script Group selects the named table script group, a list of scripts in a group, or all scripts.

dt << Select Script Group; // select all scripts groups
dt << Select Script Group( "Tabulate" ); // select Tabulate group
dt << Select Script Group( {"Tabulate", "Maps"} );// select both groups

Ungroup Scripts

Ungroup Scripts removes specified table scripts or group from the group. You can send the message to the name of the script group or a list of scripts.

dt << Ungroup Scripts( "Tabulate" );
dt << Ungroup Scripts(
	{"Tabulate: Category and Description", "Tabulate: Category, Summary, Percentage",
	"Tabulate: Category and Resolution", "Tabulate: Resolution and Description"}
);

Rename a Script Group

You can rename a table script group using Rename Script Group, specifying the existing group name, and specifying the new group name.

dt << Rename Script Group( "Maps", "Street Maps" );

Delete a Script Groups

To delete a table script group, you get it first and then delete it.

a = dt << Get Script Group( "Street Maps" );
dt << Delete Scripts( a );
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).