cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
TomF
Level II

Setting the starting directory for the "Save As" pop-up dialog with JSL

JMP Pro 16.1

 

I want to write script that brings up a "Save As" dialog box when a button is clicked, but I want to control what directory it starts in.  I do not want to save the table with its current name; I want to give the user a chance to change the name before saving.

If I run this code:

 

dtTemp = New Table("Temp");
dtTemp << Save("");

 

The Save As dialog pops up in whatever directory I last saved in.  If I try to force the directory like this:

 

dtTemp2 = New Table("Temp2");
dtTemp2 << Save As("$Documents\");

then my Temp2 table gets renamed to ".jmp" and saved in the Documents folder which is no good. I need that dialog that lets the user set the name.

 

Somewhere there is a variable where JMP or the OS is saving the last directory/path where a file was saved, I'd like to overwrite this, but I can't even find it.  I tried a few options, but none of these seems to be the right one.

 

path1 = Get Default Directory();
path2 = Get Current Directory();
path3 = Get File Search Path();

Show( path1, path2, path3);

It's worth noting that it seems the "last save directory" is stored separately for scripts and data tables which makes me think what I'm looking for is saved somehow within JMP, not the OS.

 

What I want is something like:

dtTemp = New Table("Temp");
Set Data Table Save Path ("$DESKTOP\MyDestination");
dtTemp << Save("");

Any ideas?

 

2 REPLIES 2
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Setting the starting directory for the "Save As" pop-up dialog with JSL

You could get the filename first using Pick File, and then save it.

 

Names default to here(1);

fn = pick file("Save your file", "$DOCUMENTS", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 1, "Default Filename.jmp" );

dt << Save (fn);
jthi
Super User

Re: Setting the starting directory for the "Save As" pop-up dialog with JSL

Didn't know that you could change Pick File's button text from Open to Save by changing saveFlag to 1 (have never tried it).

jthi_0-1656141886799.png

With saveFlag = 0 button will be named Open and with saveFlag = 1 it will be named Save. It won't save the file (it will just return path) so you still have to save it like @ih demonstrated (also remember to check that the returned path isn't empty).

-Jarmo