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

How do I get a script to read lines from Notepad as style names?

Guide ,
Jun 13, 2025 Jun 13, 2025

Hello, everyone.
I want to put a notepad "name.txt" in the same directory as the scripts.
The style names used in all my scripts will read the ones set in "name.txt".
This way I can change them uniformly at any time.
Is there a way to do this?

 

For example, the content of my notepad looks like this, one style name per line.
In parentheses ( ) are the style names:


paraStname(mypar)
charStname(title1)
tabStname(mytab)
footerStname(footer)
objStaname(mypic)

 

Thank you very much.

TOPICS
Bug , Feature request , How to , Performance , Scripting
2.0K
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 3 Correct answers

Community Expert , Jun 13, 2025 Jun 13, 2025

You can read a text file like this:

 

//Text file to opem. Here a file named test.txt on the desktop
var p = File(Folder.desktop + "/test.txt");
var t = readFile(p)
//an array of lines from the text file
var ta = t.split("\n")

//the returned array
alert(ta);
//array’s 2nd item
alert(ta[1])


/**
* Read a text file 
* @ param path to the file 
* @ return the text 
*/
function readFile(p) {
	var f = new File(p);
	f.open("r");  
	var x = f.read();  
	f.close();
	return x; 
}

 

 

The alerts:

 

Screen Shot 13.png

 

Screen Shot 14.png

...
Translate
Community Expert , Jun 13, 2025 Jun 13, 2025

You can check out a sample code at the following link

https://community.adobe.com/t5/premiere-pro-discussions/how-to-read-json-file-in-premiere-cep-extension/m-p/10647827#M229987

Change you input file to a JSON like the following

{
    "paraStname":"mypar",
    "charStname":"title1",
    "tabStname":"mytab",
    "footerStname":"footer",
    "objStaname":"mypic"
}

After executing the script you can access myPic with the code 

contentObj.objStaname

-Manan

Translate
Guide , Jun 14, 2025 Jun 14, 2025

@Manan Joshi @rob day 

Suddenly it worked ......

Thank you good people great good people.

 

I would like to ask:
alert(objStn); can output "mypic"
alert(contentObj); but not the whole content?

The result is: [object object]


Why?

 

This is the kind of thing that will unify the settings of all scripts now.

I wonder if it would be a waste of resources and time to call json.jsx and mystyle.json all the first time.

 

//@include "json.jsx";

var script_folder = script_dir();
var jsonFile = File(script_folder + "/m
...
Translate
Community Expert ,
Jun 17, 2025 Jun 17, 2025

Thanks for the update. What I would suggest is to take some time to analyze the error, trusting the knowledge that you know and have verified to be working and trying to understand what the error is trying to say. If you do this, spend a little time without straightaway asking for help then you would be able to write much better and complex code.

-Manan

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

@Manan Joshi 

Can I quote the path? It didn't work for me.

For example, I want to check if there is a certain folder under a certain path, and create a new one if I find that there is not.

 

"exPDFname" : "PDF",

"exPDFpath" : "Folder.desktop"
 
var exPDFname = contentObj.exPDFname;
var exPDFpath = contentObj.exPDFpath;


#target indesign;
//Detect the presence of PDF catalog
var SCRIPTS_FOLDER = decodeURI(exPDFpath);
var folder1 = Folder(SCRIPTS_FOLDER + "/" + exPDFname);
//Check if it exist, if not create it.
if (!folder1.exists) folder1.create();
if (!folder1.exists) alert("You need to run this script as Administrator\nThe folder was NOT created");

 

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

Did you write the following in JSON? And expect to get the path of desktop in the script when using this property?

exPDFpath" : "Folder.desktop"

 If so then this is not going to work. Folder is an object that makes sense inside InDesign script. Using it as a constant inside a text file will not automatically result in its evaluation.

-Manan

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

Yes, I'm trying to use this in json:
exPDFpath" : "Folder.desktop"
I hope this can be customized later.

 

Is there any way in jsx,
to convert var exPDFpath = contentObj.exPDFpath; to an object that makes sense as you say.

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

Not recommended but you can try the following

var exPDFpath = eval(contentObj.exPDFpath);

-Manan

 

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

Perfect.
So amazing.
Thank you so 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
Guide ,
Jun 18, 2025 Jun 18, 2025

There are two possibilities:
"exPDFpath" : "C:"
"exPDFpath" : "Folder.desktop"
Two inputs, is there a way to automatically determine if conversion is needed?

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

If you are using a hardcoded actual path then it needs no conversion. However, if you are using something that is actually a javascript code that would need conversion.

-Manan

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

Learning to debug your own code is part of the journey as a developer, amateur or otherwise. There is no magic solution that is going to debug errors like that. 

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