Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

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

Valorous Hero ,
Dec 01, 2023 Dec 01, 2023

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.

2023-12-01_11-57-32.png

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

Any ideas?

— Kasyan

TOPICS
Scripting
574
Translate
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

correct answers 1 Correct answer

Guide , Dec 01, 2023 Dec 01, 2023

cvsFile

 

should be csvFile 🙂

Translate
Guide ,
Dec 01, 2023 Dec 01, 2023

Maybe the scope of csvFile variable?

Translate
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
Valorous Hero ,
Dec 01, 2023 Dec 01, 2023

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

Translate
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
Guide ,
Dec 01, 2023 Dec 01, 2023

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

Translate
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
Community Expert ,
Dec 01, 2023 Dec 01, 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.

Translate
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
Guide ,
Dec 01, 2023 Dec 01, 2023

cvsFile

 

should be csvFile 🙂

Translate
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
Community Expert ,
Dec 01, 2023 Dec 01, 2023

Hilarious!

Translate
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
Valorous Hero ,
Dec 01, 2023 Dec 01, 2023
LATEST

Oops! What a stupid mistake I made! 🙂
Thank you for pointing this out.

Translate
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