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

Scripting Guide > Display Trees > Scripting the Script Editor
Publication date: 09/28/2021

Scripting the Script Editor

Even the script editor window is a display tree in JMP, which means you can write a JSL script to write and save another JSL script.

There is no New Script command. Instead, to open a new script window, you use the New Window() function and then send it a message to tell it that it’s a script window:

ww = New Window( "Window Title", <<Script, "Initial Contents" );

The last argument is optional. If you include a string, the new script window contains that string.

In the New Window example above, ww is a reference to the display box that is the entire window. To write to a script window, you first need to get a reference to the part of the display box that you can write to, which is called a script box:

ed = ww[Script Box(1)];

Using the reference ed, you can add text, remove text, and get the text that is already there.

ed << Get Text();

"Initial Contents"

Use Set Text to set all the text in the script window. The following command clears all text in the Script Window and then adds aaa=3; followed by a return:

ed << Set Text( "aaa=3;\!N" );

Use Append to add additional text to the end of the script window.

ed << Append Text( "bbb=1/10;" );
ed << Append Text( "\!Nccc=4/100;" );

Use the Get Line Text command to get the text at the line of a specified line number. Use the Set Line Text command to replace a specified line of text with new text.

ed << Get Line Text( 2 );
ed << Set Line Text( 2, "bbb = 0.1;" );

Use the Get Line Count message to get the total number of lines in the script. The Get Lines message returns a list of each line in the script as a string.

ed << Get Line Count();
ed << Get Lines();

Use the Reformat message to automatically format a script for easier reading.

ed << Reformat();

To run an entire script in a script window, use it the Run message.

ed << Run();

To close the script window without saving the script, send the window the Close Window message, just like you can do with any JMP window.

ww << Close Window( nosave );

To save and view the script, use the Save Text and Load Text File messages:

ww = New Window( "Test", <<Script, "Open(\!"$SAMPLE_DATA\Big Class.jmp\!");");
ww << Save Text( "$TEMP/Test.jsl" );
Write( Load Text File( "$TEMP/Test.jsl" ) );

Note: When the script is loaded into the script window, the window is considered “dirty” or modified. Use <<Set Dirty(0) to remove this property. Otherwise, you are prompted to save the script when you close the window.

To save the script and close the window, follow this example:

ww = New Window( "Test", <<Script, "Open(\!"$SAMPLE_DATA\Big Class.jmp\!");");
ww << Save Text( "$TEMP/Test.jsl" );
ww << Close Window();
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).