cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
nikles
Level VI

Search for filename

Hi.  Is there a way to have a script search the user's computer for a given filename and return the path?  Im using a Mac and JMP14.3 atm.  I'm interested in creating an add-in that calls another script on the user's computer, but I won't know where the user has stored the script. 

 

In the add-in, I'm thinking something like this:

 

//Add-in code

path = [command or function to search for "myscript.jsl" on user's computer and return a path];
Include(path, New Context);

//Things I've explored:

//Not certain what the "search" option does, but seemed worth a go.  
//This only returns my default directory with "myscript.jsl" appended 
//(even though there is no such file in that location)

path = ConvertFilePath("myscript.jsl", search);  

//There's also this, but same result as above:
Set File Search Path("$HOME/");
path = ConvertFilePath("myscript.jsl", search);  

//As a last resort, I looked at this, thinking maybe if I could get a list of all files, 
//I could then search the list for myscript.jsl.  Unfortunately I cannot get the "recursive" 
//option to work on my machine (Mac, JMP14.3).  I imagine this would be a very slow method 
//though as there are 1000s of files in a typical user's home directory.

y = Files In Directory("$HOME", "recursive"); //Returns {}
y = Files In Directory("$HOME", "Recursive"); //Returns {}
y = Files In Directory("$HOME", recursive); //Returns {}
y = Files In Directory("$HOME", Recursive); //Returns {}
y = Files In Directory("$HOME", Recursive(1)); //Returns {}

//All options above just return {}. I'm curious if this is unique to my setup (Mac, JMP14.3).

Other than that, I'm out of ideas.  Does anyone have any suggestions?  Thanks.

 

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

Re: Search for filename

If you need to search the whole drive you likely want to leverage any indexing the OS already did, which I think is possible using 'find' in the terminal.

 

find / -name abc.dmg

You could call this using Run Program.  I am guessing at the file path for find and the syntax, but the call might look something like this:

Run Program(
	Executable( "/usr/bin/find"),
	options( {"/ -name abc.dmg"} )
);

Some other things to consider:

  • Could you include the script in your add-in?
  • This is probably going to be slow, would it be faster to just ask the user to open the file?
  • If the user does pick the file, you could save the path and not ask on subsequent runs, or you could copy the file to the add-in folder.
nikles
Level VI

Re: Search for filename

Thanks for the suggestion ih. I looked into this, but regret to say I'm not really knowledgeable enough on the Run Program command to make this work. At first glance, it appears to require an actual file in the "Executable" field, rather than just a string. This strays into unknown territory for me unfortunately.

I've created a wish list item that is related to this: Possible to have an add-in search for a script and run it? 

I appreciated the questions at the end of your reply, and I tried to address those questions in this wishlist item post.

Thanks again for you help.