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.
This happens on Windows 10, both in ESTK and VSCode: in InDesign 2023 and 2024, Bridge 2024, ESTK.
Any ideas?
— Kasyan
cvsFile
should be csvFile 🙂
Copy link to clipboard
Copied
Maybe the scope of csvFile variable?
Copy link to clipboard
Copied
It's a local variable within the 'main' function.
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.
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.
Copy link to clipboard
Copied
cvsFile
should be csvFile 🙂
Copy link to clipboard
Copied
Hilarious!
Copy link to clipboard
Copied
Oops! What a stupid mistake I made! 🙂
Thank you for pointing this out.