cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Open a file in the operating system default program

Problem

If you need to open a file in an external program, typically the JSL Open() function will work for you. However, if you want to open a file type that JMP knows how to import, you will probably end up with the file imported instead of opened in the external program. Opening an Excel file is a common use case for this.

Solution

To do this, we can use the JSL RunProgram() function. Windows requires some special handling so that JMP is not frozen until the program closes, nor does the process need to close before JMP closes. 


/* 	Function: openFileInOSDefault
		Open file in the operating system default program
	Arguments: 
		filepath - local path file
*/
openFileInOSDefault = Function({filepath},
	If( Host is( "Windows" ),
		Run Program(
			Executable( "PowerShell.exe" ),
			Options(
				Eval Insert( "\[-Command "& {Start-Process '^filepath^'}"]\" )
			),
			Read function( "text" )
		);
	,
		RunProgram(
			Executable( "/usr/bin/open" ),
			Options( filepath ),
			ReadFunction( "text" )
		)
	);
);

Discussion

Generally, I don't think you need to understand how exactly this works and you can plug this into your scripts and call it with a path to the file you want to open.

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.