cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-246050%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9C%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%B5%B1%E9%BB%98%E8%AA%8D%E7%A8%8B%E5%BA%8F%E4%B8%AD%E6%89%93%E9%96%8B%E6%96%87%E4%BB%B6%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-246050%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CDIV%20class%3D%22lia-message-template-problem-zone%22%3E%0A%3CH2%20id%3D%22toc-hId-1648454135%22%20id%3D%22toc-hId-1761157369%22%20id%3D%22toc-hId-1761157369%22%3E%E5%95%8F%E9%A1%8C%3C%2FH2%3E%0A%3CP%3E%E5%A6%82%E6%9E%9C%E6%82%A8%E9%9C%80%E8%A6%81%E5%9C%A8%E5%A4%96%E9%83%A8%E7%A8%8B%E5%BA%8F%E4%B8%AD%E6%89%93%E9%96%8B%E6%96%87%E4%BB%B6%EF%BC%8C%E9%80%9A%E5%B8%B8%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%20JSL%20Open()%20%E5%87%BD%E6%95%B8%E3%80%82%20%E4%BD%86%E6%98%AF%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%82%A8%E6%83%B3%E6%89%93%E9%96%8B%20JMP%20%E7%9F%A5%E9%81%93%E5%A6%82%E4%BD%95%E5%B0%8E%E5%85%A5%E7%9A%84%E6%96%87%E4%BB%B6%E9%A1%9E%E5%9E%8B%EF%BC%8C%E6%82%A8%E6%9C%80%E7%B5%82%E5%8F%AF%E8%83%BD%E6%9C%83%E5%B0%8E%E5%85%A5%E6%96%87%E4%BB%B6%E8%80%8C%E4%B8%8D%E6%98%AF%E5%9C%A8%E5%A4%96%E9%83%A8%E7%A8%8B%E5%BA%8F%E4%B8%AD%E6%89%93%E9%96%8B%E3%80%82%20%E6%89%93%E9%96%8B%20Excel%20%E6%96%87%E4%BB%B6%E6%98%AF%E4%B8%80%E5%80%8B%E5%B8%B8%E8%A6%8B%E7%9A%84%E7%94%A8%E4%BE%8B%E3%80%82%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%0A%3CH2%20id%3D%22toc-hId--903702826%22%20id%3D%22toc-hId--790999592%22%20id%3D%22toc-hId--790999592%22%3E%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88%3C%2FH2%3E%0A%3CP%3E%E7%82%BA%E6%AD%A4%EF%BC%8C%E6%88%91%E5%80%91%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%20JSL%20RunProgram()%20%E5%87%BD%E6%95%B8%E3%80%82%20Windows%20%E9%9C%80%E8%A6%81%E4%B8%80%E4%BA%9B%E7%89%B9%E6%AE%8A%E8%99%95%E7%90%86%EF%BC%8C%E4%BB%A5%E4%BE%BF%20JMP%20%E5%9C%A8%E7%A8%8B%E5%BA%8F%E9%97%9C%E9%96%89%E4%B9%8B%E5%89%8D%E4%B8%8D%E6%9C%83%E5%87%8D%E7%B5%90%EF%BC%8C%E9%80%B2%E7%A8%8B%E4%B9%9F%E4%B8%8D%E9%9C%80%E8%A6%81%E5%9C%A8%20JMP%20%E9%97%9C%E9%96%89%E4%B9%8B%E5%89%8D%E9%97%9C%E9%96%89%E3%80%82%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F*%20%20Function%3A%20openFileInOSDefault%0A%20%20Open%20file%20in%20the%20operating%20system%20default%20program%0A%20Arguments%3A%20%0A%20%20filepath%20-%20local%20path%20file%0A*%2F%0AopenFileInOSDefault%20%3D%20Function(%7Bfilepath%7D%2C%0A%20If(%20Host%20is(%20%22Windows%22%20)%2C%0A%20%20Run%20Program(%0A%20%20%20Executable(%20%22PowerShell.exe%22%20)%2C%0A%20%20%20Options(%0A%20%20%20%20Eval%20Insert(%20%22%5C%5B-Command%20%22%26amp%3B%20%7BStart-Process%20'%5Efilepath%5E'%7D%22%5D%5C%22%20)%0A%20%20%20)%2C%0A%20%20%20Read%20function(%20%22text%22%20)%0A%20%20)%3B%0A%20%2C%0A%20%20RunProgram(%0A%20%20%20Executable(%20%22%2Fusr%2Fbin%2Fopen%22%20)%2C%0A%20%20%20Options(%20filepath%20)%2C%0A%20%20%20ReadFunction(%20%22text%22%20)%0A%20%20)%0A%20)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-solution-zone%22%3E%0A%3CH2%20id%3D%22toc-hId-839107509%22%20id%3D%22toc-hId-951810743%22%20id%3D%22toc-hId-951810743%22%3E%E8%A8%8E%E8%AB%96%3C%2FH2%3E%0A%3CP%3E%E9%80%9A%E5%B8%B8%EF%BC%8C%E6%88%91%E8%AA%8D%E7%82%BA%E6%82%A8%E4%B8%8D%E9%9C%80%E8%A6%81%E4%BA%86%E8%A7%A3%E5%AE%83%E7%A9%B6%E7%AB%9F%E6%98%AF%E5%A6%82%E4%BD%95%E5%B7%A5%E4%BD%9C%E7%9A%84%EF%BC%8C%E6%82%A8%E5%8F%AF%E4%BB%A5%E5%B0%87%E5%AE%83%E6%8F%92%E5%85%A5%E6%82%A8%E7%9A%84%E8%85%B3%E6%9C%AC%E4%B8%A6%E4%BD%BF%E7%94%A8%E6%82%A8%E8%A6%81%E6%89%93%E9%96%8B%E7%9A%84%E6%96%87%E4%BB%B6%E7%9A%84%E8%B7%AF%E5%BE%91%E4%BE%86%E8%AA%BF%E7%94%A8%E5%AE%83%E3%80%82%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
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.