Customizing Origin Startup Behavior with the Command Line

When Origin is started, it reads the Command Line or Target text box (depending on your version of Windows) in the Origin program icon's Properties dialog box.

By default, these text boxes start Origin by executing the Origin .EXE file - without any switches. Switches can be added to modify Origin's startup sequence.

Syntax of Command Line Arguments

All command line arguments are optional. The syntax for passing arguments to Origin is:

<Origin.EXE path and name>[-switch arg] [origin_file_name] [labtalk_scripts]

  • -switch arg
    Multiple switches can be passed. Most switches follow the above notation except -r, -r0 and -rs, which use LabTalk scripts as arguments and execute the scripts after Origin C startup compile. See the Switches table and examples below for available switches and their function.
  • origin_file_name
    This file name must refer to an Origin project file or an Origin window file. A path may be included and the file extension must be specified.
  • labtalk_scripts
    Optional script to run after the OPJ is open. This is useful when the script is very long.

 

Note: In general, the initialization switch (-i) should precede other switches if more than one switch is used.

Switches

Switch Argument Function
-A cnf file Specifies a configuration file to add to the list specified in the INI file.

Configuration files can include any LabTalk command, but typically contain menu commands and macro definitions. The file (a) should be placed at the root level in your User Files Folder, (b) must have a CNF extension (omit at the command line), and (c) cannot contain spaces in the file name. For example:

<Origin.EXE path and name> -a MyConfig

Note: When passing the .cnf file on the command line using -a switch, Origin C may not finish startup compiling, and the licensing has probably not been processed by the time the .cnf file is processed. So, when you want to include X-Functions in your .cnf file, it's better to use -r or -rs switch instead of -a.

-B <none> Run script following OPJ path-name after the OPJ is open similar to -R but before the OPJ's attached ProjectEvents.ogs, such that you can use this option to pass in variables to ProjectEvents.ogs. This option also have the advantage of using all the command line string at the end so it does not need to be put into parenthesis as is needed by -R.
-C cnf file Specifies a new configuration file to override the specification in the INI file.
Configuration files can include any LabTalk command, but typically contain menu commands and macro definitions.
-H <none> Hide the Origin application. Script Window will still show if it is open by internal control.
-HS <none> Same as -h, but in addition, it prevents the Script Window from opening. This helps scheduled tasks to run reliably.
-I ini file Specifies an initialization file to use in place of ORIGIN.INI. In general this switch should precede other switches if more than one switch is used.
-L level Specifies at which menu level to start Origin at.
-M <none> Run the Origin application as minimized.
-OCW ocw file Load the Origin C workspace file.
-P full path Directs the network version of Origin to look for client-specific files in the specified path.
-R (script) Run the LabTalk script after any specified OPJ has been loaded.

Note: This script will execute after Origin C startup compile.

-R0 (script) Run the LabTalk script before any specified OPJ has been loaded.

Note: This script will execute after Origin C startup compile.

-RS scripts Similar to -R but without having OPJ specified. All the remaining string from the command line will be used as LabTalk script and run after Origin C startup compile has finished.
-SLOG file name Send script window output to file. If no path is provided, then the file is written to the user files folder. If no file name is specified and another switch follows, like -slog -hs, then Script_Log.txt will be created in the user files folder.
-TL file name Specifies the default page template.
-TM otm file Specifies the default matrix template.
-TG otp file Specifies the default graph template. Same as -TP.
-TP otp file Specifies the default graph template. Same as -TG.
-TW otw file Specifies the template used to create the first window in the project/session. File name cannot exceed 8 characters, excluding the otw extension.
-W <none> Directs the network version of Origin to look for client-specific files in the Start In folder or Working directory.

Examples

Loading an Origin Project File

Example 1

The following is an example of a DOS *.bat file. First it changes the current directory to the Origin exe directory. It then calls Origin and passes the following command line arguments:

  • -r0 (type -b "opj will open next")
    Uses -r0 to run script before the Origin project is loaded.
  • -r (type -b "OPJ is now loaded")
    Uses -r to run script after the Origin project is loaded.
  • c:\mypath\test.opj
    Gives the name of the Origin project to open.

Please note that these -r, -r0, -rs, -b switches will wait for Origin C startup compiling to finish and thus you can use X-Functions in such script, as in:

cd "<Origin.EXE path>" <Origin.EXE name> -r0 (type -b "opj will open next") -r (type -b "OPJ is now loaded") c:\mypath\test.opj

For more complicated scripts, you will be better off putting them into an OGS file, and then running that OGS file from the command line.

Example 2

The following example will run the script code in the main section of the startup.ogs file located in the User Files Folder. When the file name given to the run.section method does not contain a path, LabTalk assumes the file is in the User Files Folder. The following command line argument illustrates use of the run.section object method:

"<Origin.EXE path and name>" -rs "run.section(startup.ogs, main)"

A simple startup.ogs file to demonstrate the above example can be:

[main]
    type -b "hello, from startup.ogs";

Run OPJ-Based Custom Program with Command-Line Control

The ProjectEvents.ogs script attached to an OPJ file can be used to create an OPJ-centered task-processing tool. In the following example, an OPJ can be used to run a program either by opening the OPJ directly, or by calling it from a command line console external to Origin. In addition, we can set a project variable in the command line to indicate whether the OPJ was opened by a user from the Origin GUI or as part of a command-line argument.

We will create an OPJ with the following ProjectEvents.ogs code:

[AfterOpenDoc]
Function doTask()
{
	type -a "Doing some task...";
	// code to do things
	type "Done!";
}
//%2 = 2 for command line, but also for dble-click OPJ
// so we better control it exactly with this variable
CheckVar FromCmdLine 0;
if(FromCmdLine)
{
	type -b "Coming from command line";
	doTask();
	sec -p 2;//wait a little before closing
	exit;
}
else
{
	type -N "Do you want to do the task now?";
	doTask();
}

To run this OPJ (call it test) from a command line, use the -B switch to ensure the FromCmdLine variable is defined before [AfterOpenDoc] is executed:

"<Origin.EXE path>" <Origin.EXE name> -b <opjpath>test.opj FromCmdLine=1

Batch Processing with Summary Report in Origin

The following example demonstrates starting Origin from a command line shell (i.e., Windows cmd) by entering a long script string containing the -rs switch.

The script performs several actions:

  1. Sets up a string variable (fname$) with multiple file names,
  2. Calls an X-Function (batchprocess) to perform batch processing using an existing analysis template,
  3. Calls an X-Function (expasc) to Export the result to a CSV file (c:\test\my batch\output.csv),
  4. Suppresses a prompt to save the Origin Project (OPJ) file (doc -s), and
  5. Exits the Origin application.

To begin, issue this command at an external, system-level command prompt (such as Windows cmd), replacing the Origin installation path given with the one on your computer or network:

"<Origin.EXE path and name>" -m -rs template$="<Origin.EXE path>\Samples\Curve Fitting\autofit.ogw"; fname$="<Origin.EXE path>\Samples\Curve Fitting\step01.dat%(CRLF)<Origin.EXE path>\Samples\Curve Fitting\step02.dat%(CRLF)<Origin.EXE path>\Samples\Curve Fitting\step03.dat%(CRLF)<Origin.EXE path>\Samples\Curve Fitting\step04.dat%(CRLF)<Origin.EXE path>\Samples\Curve Fitting\step05.dat%(CRLF)<Origin.EXE path>\Samples\Curve Fitting\step06.dat"; batchprocess batch:=template name:=template$ fill:="Data" append:="Summary" ow:=[Summary Book]"Summary Sheet"!; expasc iw:=[Summary Book]"Summary Sheet"! type:=csv path:="c:\test\my batch output.csv"; doc -s; exit;

Batch Processing with Summary Report in External Excel File

This example demonstrates using an external Excel file to generate a Summary Report using Batch Processing.

In one single continuous command line, the following is performed:

  1. Origin is launched and an existing Origin Project file (OPJ) is loaded which contains
    • an Origin workbook to be used as Analysis Template, and
    • an externally linked Excel file to be used as the report book.
  2. All files matching a particular wild card specification (in this case, file names beginning with T having the *.csv extension) are found.
  3. The batchProcess X-Function is called to perform batch processing of the files.
  4. The Excel window will contain the summary report at the end of the batch processing operation. This window, linked to the external Excel file, is saved and the Origin project is closed without saving.
  5. You can directly open the Excel file from the \Samples\Batch Processing subfolder to view the results.

To begin, issue this command at an external, system-level command prompt (such as Windows cmd), replacing the Origin installation path given with the one on your computer or network:

"<Origin.EXE path and name>" -rs string path$=system.path.program$+"Samples\Batch Processing\";string opj$=path$+"Batch Processing with Summary Report in External Excel File.opj";doc -o %(opj$);findfiles ext:="T*.csv";win -a Book1;batchProcess batch:=0 fill:="Raw Data" append:="My Results" ow:=[Book2]Sheet1! number:=7 label:=1;win -o Book2 {save -i %YReport.xls}; doc -s; exit;

Note: Additional information on batch processing from script (using both Loops and X-Functions) is available in a separate Batch Processing chapter.