How to have File.openAsString() start in a specified directory?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to have File.openAsString() start in a specified directory?

Bill Christens-Barry-2
I would like to choose and open a (text) file that is in a particular directory of my choosing. I've not found a way to have the open dialog begin in this directory unless it happens to have been the most recently visited directory. The File.openAsString() macro function needs either a complete path that includes the file name, or a null path, in which case the user must navigate to the desired directory before choosing the file. But I've not found a way to have the open dialog start where I'd like, as the OS seems to control the initial path that is used by the dialog (on macos at least).

Can this be done with existing macro functions?

Thanks.

-- equipoise

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to have File.openAsString() start in a specified directory?

Wayne Rasband-2
> On Nov 27, 2018, at 4:32 PM, Bill Christens-Barry <[hidden email]> wrote:
>
> I would like to choose and open a (text) file that is in a particular directory of my choosing. I've not found a way to have the open dialog begin in this directory unless it happens to have been the most recently visited directory. The File.openAsString() macro function needs either a complete path that includes the file name, or a null path, in which case the user must navigate to the desired directory before choosing the file. But I've not found a way to have the open dialog start where I'd like, as the OS seems to control the initial path that is used by the dialog (on macos at least).
>
> Can this be done with existing macro functions?

Use the call() macro function to call OpenDialog.setDefaultDirectory(dir), as in this example:

  dir =  "/Users/wayne/Downloads/";
  call("ij.io.OpenDialog.setDefaultDirectory", dir);
  s = File.openAsString("");
  print(s);

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html