cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
john_madden
Level VI

JMP 15 AppleScript Run Program()

I've never used Run Program() before, and I need some help. Since JMP can't open password-protected Excel files, I'm working up a little Applescript to open them and export them as unprotected .csv. I'd like to run this Applescript from within a JSL script. Maybe if it works well, I'll create a little JMP user function to wrap it, so I can simulate in JMP the ability to open password-protected Excel.

 

BUT…I'm having trouble wrangling Run Program(). A few questions.

 

1. Should my Applescript be saved as an application (.app extension) or as a script (.scpt extension).

2. My JSL syntax looks like this:

Run Program( Executable( "Users/me/Desktop/myscript.scpt" ) )

but it doesn't work, giving the following error:

launch path not accessible in access or evaluation of 'Glue' , Names Default To Here( 1 ); /*###*/Run Program(
	Executable( "/Users/me/Desktop/re.scpt" )
) /*###*/;

In the following script, error marked by /*###*/
Names Default To Here( 1 ); /*###*/Run Program(
	Executable( "/Users/me/Desktop/re.scpt" )
) /*###*/;

Again, I've tried using .app and .scpt and no extension at all -- no joy.

 

Obviously, I'm going to have to add in some additional code to get a handle on the resulting .csv export file, but for now, I just need to get off the ground with running a barebones Applescript at all.

 

Thanks for any help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
julian
Community Manager Community Manager

Re: JMP 15 AppleScript Run Program()

Hi @john_madden,

 

I would save your script as .app, and then use something like the following to open that application, which uses the 'open' executable to open the .app:

 

 

Run Program(
	Executable( "/usr/bin/open"),
	options( {"/users/me/Desktop/myscript.app"} )
);

I hope this helps get you started!

@julian 

 

View solution in original post

5 REPLIES 5
julian
Community Manager Community Manager

Re: JMP 15 AppleScript Run Program()

Hi @john_madden,

 

I would save your script as .app, and then use something like the following to open that application, which uses the 'open' executable to open the .app:

 

 

Run Program(
	Executable( "/usr/bin/open"),
	options( {"/users/me/Desktop/myscript.app"} )
);

I hope this helps get you started!

@julian 

 

john_madden
Level VI

Re: JMP 15 AppleScript Run Program()

Perfect!! Thanks!!!
john_madden
Level VI

Re: JMP 15 AppleScript Run Program()

Just a little followup on this, maybe some Mac users might find useful.

The Applescript idea didn't work out -- not because of JSL, but because of limitations in MSExcel applescripting under OSX 10.15. (Save commands in Excel no longer work right, apparently due to sandboxing; I'm told Microsoft needs to update its Applescript support. )

Instead, I decided to script what I needed using Keyboard Maestro (KM), which is a very fine OSX scripting/macro app. (I recommend it highly -- I have no conflicts of interest.)

I wrote the script I needed in KM. Then I wrote a little JSL function that invokes a KM script:

 

Add Custom Functions(
	New Custom Function(
		"ex",
		"Run KMScript",
		Function( {scriptID, paramlist = {}},
			{paramstring},
			paramstring = Concat Items( paramlist );
			Run Program(
				Executable( "/usr/bin/osascript" ),
				Options(
					"-e tell application \!"Keyboard Maestro Engine\!" to do script \!"" || scriptID || "\!" with parameter \!"" || paramstring ||
					"\!""
				)
			);
		)
	) << Prototype( "ex:Run KMScript( scriptID as string, < {param1 as string, param2 as string, etc.} > )" ) << Parameter( "String", "scriptID" ) <<
	Parameter( "List", "parameter(s)" ) << Formula Category( "Utility" ) << Description(
		"Runs a Keyboard Maestro script. The KM scriptID is a UUID; you can reveal and copy it by opening the 'Or trigger by shell script' text box at the top of your KM macro window. The (optional) parameters to the KM script can be retrieved inside the KM macro using the KM '%TriggerValue' token. KM receives them as a single concatenated string of space-separated values."
	)
);

Right now, I'm using this within my JSL to invoke a KM macro that opens the protected Excel file in Numbers, unprotects it, saves it as csv, opens it in JMP, then closes Numbers. It works fine.

Hope somebody else might find this useful.

 

julian
Community Manager Community Manager

Re: JMP 15 AppleScript Run Program()

This is fantastic, John! So glad you shared this, I’m positive it will be helpful to someone.

@julian
john_madden
Level VI

Re: JMP 15 AppleScript Run Program()

Thanks, Julian.

Here's a slightly improved version, that allows you to return a value from the KM macro by including a KM "Set System Clipboard to Text…" action as the last action of your KM script. The JSL function then uses the clipboard contents as its function return value.

Also, I realized you don't have to use the KM macro UUID; it works equally well if you just use the KM macro's plain-vanilla name.

Add Custom Functions(
	New Custom Function(
		"ex",
		"Run KMScript",
		Function( {scriptID, paramlist = {}},
			{paramstring, savedClipboard, macroResult = ""},
			paramstring = Concat Items( paramlist );
			savedClipboard = Get Clipboard();
			Run Program(
				Executable( "/usr/bin/osascript" ),
				Options(
					"-e tell application \!"Keyboard Maestro Engine\!" to do script \!"" || scriptID || "\!" with parameter \!"" || paramstring ||
					"\!""
				)
			);
			macroResult = Get Clipboard();
			Set Clipboard( savedClipboard );
			Return( macroResult );
		)
	) << Prototype( "ex:Run KMScript( scriptID as string, < {param1 as string, param2 as string, etc.} > )" ) << Parameter( "String", "scriptID" )
	 << Parameter( "List", "parameter(s)" ) << Formula Category( "Utility" ) << Description(
		"Runs a Keyboard Maestro (KM) script. The KM scriptID is either the KM macro's name or UUID. (You can reveal and copy the UUID by opening the 'Or trigger by shell script' text box at the top of your KM macro window.) The (optional) parameters to the KM script can be retrieved inside the KM macro using the KM '%TriggerValue%' token. KM receives them as a single concatenated string of space-separated values. If you want to return a value from KM, push it to the system clipboard before exiting the macro. This function will grab the clipboard contents and use as the function return value. (The function saves and restores the pre-invocation clipboard state, so the system clipboard is unaffected by the function.)"
	)
);