Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


[Jsx] Not able to navigate using File.openDialog and using a filter

Contributor ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

Hi,

 

With this post I would like to ask a question. I'm having an issue using a filter in the File.openDialog window. When applying a filter, I'm no longer able to browse to subfolders.

 

I'm using ...

     var returnValue = "";

     var selectedFile = File.openDialog("Choose a CSV File", filterFiles, false);
     if (selectedFile != undefined) {
          returnValue = selectedFile.fsName;
     }
 
    function filterFiles(file) {
        if (file.name.match(/\.csv$/)){ return true }
        return false;
    }
 

When changing the filter to the code below, It works, but not on the first attempt. I have to select a folder, select another folder, and then go to the previous one, the be able to select a subfolder. And this for each subfolder...

 

    function filterFiles(file) {
       var myFolder = Folder(file.fsName);
       if (file.name.match(/\.csv$/) || (myFolder.exists && myFolder.constructor == Folder)) { return true }
             return false;
       }
   }
 
I'm using Os X 10.15.7 and the latest version of Indesign..
 
Thanx
 
 
TOPICS
Scripting

Views

66

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

I don't have a Mac at hand to test it, but try this function:

var xmlFile = File.openDialog("Choose an XML file", (File.fs == "Macintosh") ? FileFilter : "XML files:*.xml;All files:*.*");
	
function FileFilter(file) {
	var extention = ".xml";
	var lowerCaseName = file.name;
	lowerCaseName.toLowerCase();
	
	if (lowerCaseName.indexOf(extention) == file.name.length - extention.length) {
		return true;
	}
	else if (file instanceof Folder) {
		return true;
	}
	else {
		return false;
	}
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

Thank you for sharing your script. This seems to work but it looks like there is a bug in the UI. All folders are grayed out, but it seems they can be clicked, sometimes on the filename, sometimes on the triangle icon.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 15, 2021 Aug 15, 2021

Copy link to clipboard

Copied

LATEST

That is great

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

Does this work?:

 

var returnValue = "";

var selectedFile = File.openDialog("Choose a CSV File", filterFiles, false);
if (selectedFile != undefined) {
    returnValue = selectedFile.fsName;
}
 
function filterFiles(file) {
    if (file.name.match(/\.csv$/i) || file instanceof Folder){return true} 
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 15, 2021 Aug 15, 2021

Copy link to clipboard

Copied

Try this :

var returnValue = "";
var selectedFile = File.openDialog("Choose a CSV File", "*.csv", false);
if (selectedFile != undefined) {
    returnValue = selectedFile.fsName;
    }

In Windows, a filter expression such as "Javascript files:*.jsx;All files:*.*". In Mac OS, a filter function that takes a File instance and returns true if the file should be included in the display, false if it should not.

 

Best

Sunil

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines