3.3.2.51 Run(command)

Execute a script file or run a Windows program.

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 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.

-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.

-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.

-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 n 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 run recalculate again.

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

syntax: run -cr
syntax: run -cr 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 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 operations to update to completion

Syntax: run -p au;

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

-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;

-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)

-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

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)

-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.

-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.


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 runs the specified script file.

run c:\c\test\mytest.ogs;

Example 3

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

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