Copy link to clipboard
Copied
Hi, everybody:
I was trying to run several scripts at once with this simple lines of javascript
app.doScript(File("/Users/… Script1.jsx"), ScriptLanguage.JAVASCRIPT);
app.doScript(File("/Users/… Script2.jsx"), ScriptLanguage.JAVASCRIPT);
app.doScript(File("/Users/… Script3.jsx"), ScriptLanguage.JAVASCRIPT);
app.doScript(File("/Users/… Script4.jsx"), ScriptLanguage.JAVASCRIPT);
app.doScript(File("/Users/… Script5.jsx"), ScriptLanguage.JAVASCRIPT);
app.doScript(File("/Users/… Script6.jsx"), ScriptLanguage.JAVASCRIPT);
To facilitate the reading of this post I simplified the name and the path of each script
It runs perfect untill Script4.jsx. Indesign applies it but shows an error 21 message (undefinded is not an object), and stops the following scripts application
When I run only Script4.jsx or the same list but one by one, there's no error message. The problem happen only when it's call from the batch script.
Script4.jsx is an extended version of Green4Ever's script posted in Apply Master Page using Paragraph Style
This are the whole lines I'm using
var myDocument = app.activeDocument;
var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
var myPage = myDocument.pages;
for(i=0; i<myParas.length; i++)
{
if(myParas.appliedParagraphStyle.name == "Tit1")
{
//Works only in CS5 and later
myParas.parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-master");
}
if(myParas.appliedParagraphStyle.name == "Tit2")
{
//Works only in CS5 and later
myParas.parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-master");
}
if(myParas.appliedParagraphStyle.name == "Tit3")
{
//Works only in CS5 and later
myParas.parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("D-master");
}
if(myParas.appliedParagraphStyle.name == "Tit4")
{
//Works only in CS5 and later
myParas.parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("D-master");
}
}
Extended Toolkit debugging tool show an error in line 23, but I can't realize what is about.
I'll really appreciate any help.
Thanks
I don't thing sleep will help in this case.
Try myDoc.recompose ()
Copy link to clipboard
Copied
If myParas in line 23 is e.g. in overset text, it doesn't have any parentTextFrames. Run scripts 1, 2, and 3, then check the state of the document.
Copy link to clipboard
Copied
Peter, thanks for your answer.
I am very glad to read you because the little I have learned from JavaScript and Grep in InDesign has been through your work and your books.
Following your observation, I execute 1,2 and 3, without problems. When running the 4, I get the same error but now I understand that the Smart Text Reflow does not have enough time to create pages and distribute text before the next statement of the script is executed.
Is there any way to make the script wait for the Smart Text Reflow to finish its work before running the next line?
Thanks in advance.
Copy link to clipboard
Copied
You can add this line:
$.sleep (500);
If that's not enough, try changing 500 to 1000. Or even more. The numbers are milliseconds.
Copy link to clipboard
Copied
Thanks, Peter. I'm trying but still same results.
Copy link to clipboard
Copied
I think, Peter, my problems is that I don't know where to put the line you gave me. After or before Line 23? in a variable? In batch script? I tried all this ones, and none resolve the problem.
Copy link to clipboard
Copied
It should go (I think) between scripts3 and 4. So you can add it as the last line in script 3 or the first line in script 4.
Does that work?
P.
Copy link to clipboard
Copied
Trying right now
Copy link to clipboard
Copied
Nop, doesn't work either. I think the goal would be not to wait a specific amount of time, but wait until there will be no overset text
Copy link to clipboard
Copied
Well, usually putting a script to sleep for a bit solves timing problems. Maybe the timer itself keeps the script busy so that nothing else happens. Clutching at straws here now -- maybe try the sleep clause for a bit, then test whether there are overset stories. If there are, sleep a bit more. In general terms, 'while there are overset stories, wait a bit'. perhaps something like this (untries):
while (app.documents[0].stories.everyItem().overflows.join().indexOf('true') >= 0) {
$.sleep(1000);
}
A problem may be that the script gets stuck on documents with stories that are overset because they're, well, overset permanently, not because of being not yet processed, if you see what I mean.
Copy link to clipboard
Copied
Thanks for your advices, Peter. I let you know if I find any alternative to make this work.
Copy link to clipboard
Copied
I don't thing sleep will help in this case.
Try myDoc.recompose ()
Copy link to clipboard
Copied
¡AMAZING, Trevor! Just what I need and thes best of all… ¡is so simple!
Thanks a lot… I will buy you a coffe, at leats… any time you come to Mexico City.
Copy link to clipboard
Copied
Nice one, Trevor -- book yourself on a flight to Mexico City for a coffee!