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

File.openDialog(); What is the result? What if I only have the path?

Guide ,
Jun 28, 2025 Jun 28, 2025
Whether it's an object or a path is indistinguishable.
 
I don't want the dialog to open, I want it to open the file pointed to by the path by default, what should I write?

var file = File.openDialog();
alert("file:" + file);
Below is the result after I choose to select "my.json":

dilog.png

 


If I don't want to do it manually, it it directly opens this path “pathToMyJSONFile” (pathToMyJSONFile = File($.fileName).parent.parent + ‘/PubLib/my.json’;)

How do I change it?
var file = File.open(pathToMyJSONFile);
This seems wrong.

 

alert(pathToMyJSONFile); results in this:

 

pathToMyJSONFile.png

TOPICS
Scripting
147
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

Community Expert , Jun 28, 2025 Jun 28, 2025

Something like this would read the contents of a text file:

 

var p = File(Folder.desktop + "/test.json");
var t = readFile(p)
alert(t);
  
/**
* Read a text file 
* @ param the file path of the file
* @ return the text in the file
*/
function readFile(p) {
	var f = new File(p);
	f.open("r");  
	var x = f.read();  
	f.close();
	return x;
}

 

Screen Shot 7.png

Translate
Guide ,
Jun 28, 2025 Jun 28, 2025

Tried it out. I tried multiple ......
Looks like this:
file = File(pathToMyJSONFile);

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 ,
Jun 28, 2025 Jun 28, 2025

Something like this would read the contents of a text file:

 

var p = File(Folder.desktop + "/test.json");
var t = readFile(p)
alert(t);
  
/**
* Read a text file 
* @ param the file path of the file
* @ return the text in the file
*/
function readFile(p) {
	var f = new File(p);
	f.open("r");  
	var x = f.read();  
	f.close();
	return x;
}

 

Screen Shot 7.png

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 ,
Jun 28, 2025 Jun 28, 2025
LATEST

Hi rob day.

I tried out this one.
Thank you very much.

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 ,
Jun 28, 2025 Jun 28, 2025

File.open() will not open a json or text file—open() is expecting an InDesign file path— .indt, .indd, idml

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