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

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

Guru ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

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

Views

227

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

correct answers 1 Correct answer

Guide , Dec 01, 2023 Dec 01, 2023

cvsFile

 

should be csvFile 🙂

Votes

Translate

Translate
Guide ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

Maybe the scope of csvFile variable?

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

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

Votes

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

Copy link to clipboard

Copied

cvsFile

 

should be csvFile 🙂

Votes

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

Copy link to clipboard

Copied

Hilarious!

Votes

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

Copy link to clipboard

Copied

LATEST

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

Votes

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