Run(command)

Execute a script file or run a Windows program.

Contents

Syntax:

run [option] argument
Note: The run command executes on a line-by-line basis. Multi-line structures must include the line continuation character "{" in the same line as the structure initiator (i.e., conditional statement, function definition, etc.), as in the following example:


This set of statements will work properly with the run command:

if (condition) {
            // True condition statements
 } 
else {
            // False condition statements
 }

This set of statements will NOT work properly with the run command:

if (condition) 
      {
            // True condition statements
      } 
else 
      {
            // False condition statements
      }

The run.section() object method does not have line-by-line limitation and provides greater flexibility for script file execution.

Options:

no option; Run the script file scriptfileName

Syntax: run scriptfileName

Run the script file scriptfileName.

This is an outdated way to run scripts and it SHOULD NOT BE USED. To run script files or portions of script files, use the run object.

-au value; Change the recalculate mode for the entire project

syntax: run -au value [UID]

Minimum Origin Version Required: 8.5.1

When not specifying UID, value can be:

0: Set recalculate mode to None (remove recalculation).
1: Set recalculate mode to Auto.
2: Set recalculate mode to Manual.

When specifying UID, change the recalculate mode only for the operation specified with UID.

run -au 1;  // Set recalculate mode to Auto
run -au 0 779;   // Set operation with UID 779 to None(delete it) but keep outputs

To get the UID of an operation, keep the Script Window open, click on the green lock associated with this operation and select Show Info context menu. The returned message contains the UID for this operation.

Note: run -au 0; is destructive in the sense that you can no longer use run -au 1; or run -au 2; since all operation objects have been removed.

-aub value UID; block or unblock recalculation for a specific operation

syntax: run -aub value [UID]

Block or unblock recalculation for a operation specified with UID.. If UID is omitted, it will work on all operations. value = 0: unblock, value = 1: block.

range aa=[book1]sheet1!col(2); //suppose recalculation on col(2) is blocked
Uid=aa.getop();
run -aub 0 $(Uid);

You can get the UID number of an operation by method getop().

-auc UID; Open dialog to change parameters for a specific operation

syntax: run -auc [UID]

Open dialog to change parameters for a operation specified with UID.

run -auc 804; /// 804 is operation UID

You can get the UID number by running list op/opi/opo command introduced in this page.

If the active worksheet is a hierarchical sheet, UID can be omitted. Since the hierarchical sheet contains single operation only, running

run -auc;

directly will open that operation dialog in the active sheet.

-auf; Trigger all recalculation

Syntax: run -auf n [m]

Minimum Origin Version Required: 2015 SR1

where n can be 0,1,2

n Meaning
0 Trigger all recalculation related to current Worksheet
1 Trigger all recalculation related to current Workbook
2 Trigger all recalculation related to current Project

where m can be 0,1

m Meaning
0 Trigger all recalculation now
1 Trigger all recalculation on idle
run -auf 1 1;
//It is the same as "page -uo"
//Trigger recalculation for all the operations in the active Workbook .

Note:

  • If the recalculate mode is Auto, the results will be updated automatically.
  • If the recalculate mode is Manual, the results will not be updated until you run recalculate again.

-aud value; Change the Recalculate Mode for the current folder (open)

syntax: run -aud value

Minimum Origin Version Required: 2024b

Chage the Recalculate Mode for the current folder but no recursive. value can be:

0: Set Recalculate Mode to None (remove recalculate operations).
1: Set Recalculate Mode to Auto.
2: Set Recalculate Mode to Manual.

If current folder contains any shortcut window, this command includes shortcut windows by default. If you don't want to include shortcuts, use
syntax: run -aud value 0

in which the last value 0 means exclude shortcut windows. If any values other than 0, e.g. 1, means including shortcut window.

For example, run the following command to remove all operations in the current folder except shortcut windows.

run -aud 0 0;
Note: run -aud 0; is destructive in the sense that you can no longer use run -aud 1; or run -aud 2; since all operation objects have been removed.

-audr value; Change the Recalculate Mode for the current folder (recursive)

syntax: run -audr value

Minimum Origin Version Required: 2024b

Chage the Recalculate Mode for the current folder and its sub folders. value can be:

0: Set Recalculate Mode to None (remove recalculate operations).
1: Set Recalculate Mode to Auto.
2: Set Recalculate Mode to Manual.

If current folder contains any shortcut window, this command includes shortcut windows by default. If you don't want to include shortcuts, use
syntax: run -audr value 0

in which the last value 0 means exclude shortcut windows. If any values other than 0, e.g. 1, means including shortcut window.

For example, run the following command to remove all operations in the current folder except shortcut windows.

run -audr 0 0;
Note: run -audr 0; is destructive in the sense that you can no longer use run -audr 1; or run -audr 2; since all operation objects have been removed.

-aul value; Change the Recalculate Mode for the ative layer

syntax: run -aul value

Minimum Origin Version Required: 2024b

Chage the Recalculate Mode for the active page (worksheet, matrix sheet, or graph layer). value can be:

0: Set Recalculate Mode to None (remove recalculate operations).
1: Set Recalculate Mode to Auto.
2: Set Recalculate Mode to Manual.
Note: run -aul 0; is destructive in the sense that you can no longer use run -aul 1; or run -aul 2; since all operation objects have been removed.

-aup value; Change the Recalculate Mode for the ative page

syntax: run -aup value

Minimum Origin Version Required: 2024b

Chage the Recalculate Mode for the active page (workbook, matrix book, or graph window). value can be:

0: Set Recalculate Mode to None (remove recalculate operations).
1: Set Recalculate Mode to Auto.
2: Set Recalculate Mode to Manual.
Note: run -aup 0; is destructive in the sense that you can no longer use run -aup 1; or run -aup 2; since all operation objects have been removed.

-cr[ filename]; Remove file(s) from Code Builder Workspace

syntax: run -cr [<path>\filename]

Removes the specified file from the Temporary and User folders in Code Builder. If filename is specified, it must include the full path. If no filename is given, all files are removed from the Temporary and User folders.

-cra; Remove Temp and User files from Code Builder Workspace

syntax: run -cra

Clean Temporary, User and User [AutoLoad] folders, plus delete any existing [OriginCAuto] section in the user's Origin.ini file (A section named as [OriginCAuto] is added to Origin.ini when you add files to User [AutoLoad] in Code Builder). Makes no changes to the System folder.


-e[p]; Execute the following text as if it were typed into the Windows Run dialog box

Syntax: run -e text or -ep text

Both will execute the following text as if it were typed into the Windows Run dialog box (from the Windows Start menu).

If a program is in the Windows system PATH then no path is needed. Since Explorer is the default shell for Windows, -ep is the same as -e.

// Notepad is generally in Windows PATH so no path needed
// Open Origin's INI file in Notepad. Script waits for Notepad to close.
run -ep notepad %YOrigin.ini;
ty -a Notepad closed.;
// Open your User Files Folder
run -e explorer %Y; // -ep would behave the same as -e
ty -a My UFF is open in Explorer.;
// Word is not usually in Windows PATH so path must be included
string strFile$ = system.path.program$ + "TXTemplate.rtf";
run -ep C:\Program Files (x86)\Microsoft Office\Office12\winword.exe %(strFile$);
ty Done with Word.;
Note: The difference between run -e and run -ep is that run -e would execute the external program and continue running scripts; while run -ep would execute the external program and pause scripts until the external program closes.

-lk; Link to open a Range, external link, help document or Note window

Syntax: run -lk "range://RangeName" or "http: //URL" or "https: //URL" or "help://HelpPage" or "help://quick/Keyword" or "notes://NotesWindowName"

This command supports hyperlinking to open an internal window, an external link, or a help document page
Range://: a range inside the project.
http:// or https://: an external link.
help://: link to the Origin Help document.
help://quick/Keyword: open the quick help window with the option to specify keyword(s) for search (e.g. run -lk "help://quick/descriptive statistics";).
notes://: link to the Notes window.

See Link Notations in the LabTalk Reference section.

-oc; Execute the named Origin C function

Syntax: run -oc func arg

This command will invoke an Origin C function in LabTalk. This is needed because of possible name conflict between X-Function, ogs file, LabTalk Functions etc. Also, there are some Origin C functions that were written to be callable only by the run -oc command, via the #pragma labtalk(2), to prevent the name polution problem for the LabTalk environment. All Origin C functions compiled with #pragma labtalk(2) will not be visible to LabTalk directly, you can use them only via run -oc

-p au; Force all pending project operations to update

Syntax: run -p au;

Any script which follows waits for all pending operations in the Origin project to update to completion.

-p aub; Force all pending book operations to update

Syntax: run -p aub;

Any script which follows waits for all pending operations in the active book to update to completion.

-p aubd; Force all pending book operations and descendant operations to update

Syntax: run -p aubd;

Any script which follows waits for all pending operations in the active book, plus any descendants, to update to completion.

-p aui UID; Force a specific pending operation to update to completion

Minimum Origin Version Required: 9.1 SR2

Syntax: run -p aui UID

The operation with the specified UID will be forced to update to completion before executing any script that follows.

To get the UID of an operation, keep the Script Window open, click on the green lock associated with this operation and select Show Info context menu. The returned message contains the UID for this operation.

Note: Pending operations are indicated by a yellow lock icon. This shows the source data for an operation has changed and the output is not updated. In order to pause an executing script for specific number of seconds, use the sec -p command.
//Force the operation with UID 803 to recalculate
run -p aui 803;
//Force any pending operation to recalculate
run -p au;

-p auid UID; Force recalculation of operation "UID" descendant operations

Syntax: run -p auid UID;

Any script which follows waits for operation UID, plus any descendants, to update to completion.

-p auw; Force all pending sheet operations to update

Syntax: run -p auw;

Any script which follows waits for all pending operations in the active sheet to update to completion.

-p auwd; Force all pending sheet operations and descendant operations to update

Syntax: run -p auwd;

Any script which follows waits for all pending operations in the active sheet, plus any descendants, to update to completion.

-py; Execute Python Command Line

Minimum Origin Version Required: 2015 SR0

Syntax: run -py Python Statement(s)

Run Python statement(s) (i.e. command lines). The Python Statements should be a string variable with the Python command lines to be executed.

You can directly call the Python command:

run -py print('Hello Origin');
// It runs the Python command print('Hello Origin')
// It should output the string "



Hello Origin" in the Script Window

Also, you can pass the Python command line(s) to a string variable in LabTalk:

// Define the Python command line(s) as a LabTalk string variable
// %(CRLF) is the LabTalk keyword to indicate carriage return, i.e. start new line
str$ = "a = 2 ** 8%(CRLF)print(a)";
// Execute Python command lines
run -py %(str$);
// ** is the Exponent operator in Python
//It should return 256, i.e. 2 to the power 8

It is equivalent to the object method run.python("Python Statements", 0). (i.e. if the option is set to 0 or default)

-pyb; Call the Python Code Attached to Text Object

Minimum Origin Version Required: 2021

Syntax: run -pyb objectName;

Run Python code entered on the Programming tab of the text object. Normally, the run -pyb command would be executed from a button object (second text object set to trigger on Button Up).

For example, make a text object then open its Properties dialog and on the Programming tab set Name = "abc" and enter this into the script box:

print ("Hello World!");

Make a second text object (name unimportant), open Properties > Programming tab and set Script Run After to Button Up and enter this into the script box:

run -pyb abc;

Clicking the button should trigger code attached to the text object and print "Hello World" to the Script Window.

-pye; Evaluate Python Expression

Minimum Origin Version Required: 2015 SR0

Syntax: run -pye Python Expression Evaluate Python expression(s) . The Python Expression should be a string variable with the Python expressions to be evaluated.

For example,

run -pye 2 ** 5;

// It evaluates the Python expression 2 ** 5, ** is the Exponent operator in Python
// It outputs the evaluated value 32, which is 2 to the power 5

It is equivalent to the object method run.python("Python Expression", 1). (i.e. if the option is set to 1)

-pyf; Execute Python File

Minimum Origin Version Required: 2015 SR0

Syntax: run -pyf Python File Path and Name [arg1 arg2 arg3 arg4 arg5]

Run Python file, the Python File Path and Name should be a string variable with the .py file path and name to be executed.

Note that if the .py file locates in the User Files Folder, it is not needed to specify the file path, if not, always need to specify the full file path.

For example, suppose there is a test.py file under the User Files Folder of Origin, you can run the following LabTalk script:

// Make sure script execution is set to LabTalk
run -pyf "test.py";
// This will execute the script within the file test.py

Sometimes you will need to specify the full file path for the .py file:

// Define a string for the file path and name of the .py file
string str$ = system.PATH.PROGRAM$ + "\Samples\Python\ListMember.py";
// Run the .py file

run -pyf %(str$);  
 
// This .py file list all provided functions in PyOrigin module

It is equivalent to the object method run.python("Python File", 2). (i.e. if the option is set to 2)

Arguments can be added in the call. Suppose you have a Python file "test.py" in the User Files Folder.

import sys
if __name__ == '__main__':
    print(len(sys.argv))
    print(sys.argv[1])
    print(sys.argv[2])

Variables can be passed from Labtalk to Python file by:

double var1 = 123.456;
string var2$ = 'hello';
run -pyf test.py "$(var1)" "%(var2$)";

-pyp; Execute the Python file attached to the Origin project file

Minimum Origin Version Required: 2015 SR0

Syntax: run -pyp Python File Name

The Python File Name should indicate a Python file which is attached to the Origin project, i.e. which has been added to the Project folder of Code Builder. The file extension (.py) can be included but is not required.

As an example, you can open the SendDataToWks.opj file under <Origin EXE Folder>\Samples\Python\ path and run the script:

run -pyp SendDataToWorksheet.py;
// Alternatively, run the following is equivalent
// run -pyp SendDataToWorksheet;

Note: The script above is associated with the Run SendDataToWorksheet.py button in worksheet.

-pyr; Reset the Origin Python environment

Minimum Origin Version Required: 2021b

Syntax: run -pyr


-w[u] Bookname [colIndex]; Execute Column Formula

Syntax: run -w or -wu

-w
Execute column formula with undo
-wu
Execute column formula without undo and thus faster


// the following script print out the time it takes to run
// formula of col(2) in Book1's active sheet
sec;
run -wu Book1 2;
watch;

-ws; Execute the script in worksheet script panel

Syntax: run -ws

Execute the script in worksheet script panel.

-xf; Execute the X-Function named xfname

Syntax: run -xf xfname

Execute the X-Function named xfname. Normally, you can execute a LabTalk callable X-Function directly, but since the current working directory might have an ogs file with the same name, the run -xf command allows for reliable way to call an X-Function.

-xfm; Launch non-Labtalk-accessible X-Function named xfname

Syntax: run -xfm xfname

Open the Labtalk not accessible X-Function dialog.


Examples:

Example 1

The following script opens Notepad and loads the Origin.INI file.

run -e notepad %Yorigin.ini;

Notepad does not need a path because it is typically found in Windows default PATH. The %Y tells Notepad the path to your Origin.INI.


Example 2

The next script goes to column 1, row 10 in the Book1 sheet1.

run -LK "Range://[Book1]sheet1!col(1)[10]";