Skip to main content
Kasyan Servetsky
Legend
December 1, 2023
Answered

[JS] Problem with checking if the file was selected in the dialog box

  • December 1, 2023
  • 2 replies
  • 940 views

Dear forum,

 

Though I have done this many times before, today I encountered a strange problem.

I want to make sure that the user selects a file before the script continues:

main();

function main() {
     if (File.fs == "Macintosh") {
		var csvFile = File.openDialog("Select a CSV File", function (f) { return (f instanceof Folder) || f.name.match(/\.csv$/i);} );  
     } else {  
		var csvFile = File.openDialog("Select a CSV File","CSV files:*.csv;All files:*.*");  
     }  

	if (cvsFile != null) {
		// do something
	}
}

The file has been selected and its properties are visible in the data browser, but the script throws an error: the file is undefined.

This happens on Windows 10, both in ESTK and VSCode: in InDesign 2023 and 2024, Bridge 2024, ESTK.

Any ideas?

— Kasyan

This topic has been closed for replies.
Correct answer Pickory

cvsFile

 

should be csvFile 🙂

2 replies

Peter Kahrel
Community Expert
Community Expert
December 1, 2023

This stopped working for me too. And so does Folder('xyz').openDlg().

No idea what's going on or how to work around it.

PickoryCorrect answer
Legend
December 1, 2023

cvsFile

 

should be csvFile 🙂

Peter Kahrel
Community Expert
Community Expert
December 1, 2023

Hilarious!

Legend
December 1, 2023

Maybe the scope of csvFile variable?

Kasyan Servetsky
Legend
December 1, 2023

It's a local variable within the 'main' function.

Legend
December 1, 2023

It is declared in the if, which makes it local to the if, I think. Certainly in C it would be that way.