Copy link to clipboard
Copied
#targetengine "session"
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
myStory.trackChanges = true;
I placed this script in the Startup Script folder but it gives me an error on line 3. When i have the script in the Normal Script folder and Click on it it works.
Please use the following code and let me know if all is well. I have made some modifications and explained below:
...#targetengine session
var myEventListener = app.eventListeners.item("TurnTCon");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener("afterOpen", doJob1 );
myEventListener.name = "TurnTCon";
}
function doJob(event) {
try{
if(event.parent.constructor.name == "Document") {
var myDocument = event.parent;
if(myDocument
Copy link to clipboard
Copied
I was hoping to get this to Turn on Track Changes On every document i open. I got the error to quit but it still does not turn on automatically. Here's what i did.
#targetengine "session"
function trackChanges()
{
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
myStory.trackChanges = true;
}
Copy link to clipboard
Copied
try this,
save this code in startup folder
var
myEventListener = app.eventListeners.item("xx"); //xx is script name whatever you give
if (!myEventListener.isValid) {
myEventListener = app.addEventListener( "afterOpen", doJob );
myEventListener.name = "xx"; //replace xx with script name
}
function doJob() {
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
myStory.trackChanges = true;
}
Copy link to clipboard
Copied
You can put the below in startup script:
app.addEventListener(Document.AFTER_OPEN, afterDocOpen);
function afterDocOpen(event) {
if(event.parent.constructor.name == "Document") {
var myDocument = event.parent;
var myStory = myDocument.stories.item(0);
myStory.trackChanges = true;
}
}
Above solution by tpk1982 will always pick the document at index 0. It might not work when you open multiple documents at same time.
Copy link to clipboard
Copied
So far neither one works I still Have to turn on the Track CHanges manually. By clicking the other script i use that i want to auto start.Where am i going wrong? I Tried first to type in the codes you guys gave above so that way I get used to it. But i figrued i typed something wrong. Then i Tried to copy and paste. ANd nither turn on Track Changes When a document is Opened or Created.
Copy link to clipboard
Copied
Just a quick question so when i make a stratup script will i always need a EventListener? or is it on a per script basis. Meaning depends on the script.
Copy link to clipboard
Copied
It is not mandatory to have eventlistener in your startup script. It depends on what you what to implement.
In your case, you always want to run your script on document-open.
So, we need to listen to afterOpen event.
Copy link to clipboard
Copied
It wont turn on when the document is created or opened. I tried my script name with and with out the file extension at the end. Here's what i added.. The TurnTCon is the name of the script that you see below. I also tried my TCon in the main scripts folder that works but it will not run still. Does the script need to have a delay on it so it knows when the document is opened?
var
myEventListener = app.eventListeners.item("TurnTCon"); //This is the name of the script.
if (!myEventListener.isValid) {
myEventListener = app.addEventListener( "afterOpen", doJob );
myEventListener.name = "TurnTCon"; //This is the name of the Script
}
function doJob() {
var myDocument = app.documents.item(0);
var myStory = myDocument.stories.item(0);
myStory.trackChanges = true;
}
Copy link to clipboard
Copied
I think i may see the problem. Each file has multiple Text boxes. Even the script i use only allows me to turn the Track Chages on (per text box that my cursor is in.) could this be the problem?
Copy link to clipboard
Copied
I only tried to troubleshoot the issue you were facing with the script.
With the code you have written recently, it will always turn on track changes for the FIRST story of the FIRST document in the InDesign session. It seems you want for all stories of any document.
Let me know the exact requirement. Hope you understood the issue now.
Copy link to clipboard
Copied
Its mostly working as stated above. I'm wanting this to script to turn Track Changes on for every Document. The documents i already have created as well as the ones I Create from scratch. So far its working for the Creation of a file. But as for The documents that i already have built (Which is ALOT) it will not turn it on.
Copy link to clipboard
Copied
Please share again the script you have in place. So, I can see what is wrong with it.
It seems you are having: var myDocument = app.documents.item(0);
Copy link to clipboard
Copied
try this
var myDocument = app.activeDocument;
var myStory=myDocument.stories.everyItem();
myStory.trackChanges = true;
Copy link to clipboard
Copied
Yes, that is true.
If you have app.documents.item(0) then replace it with app.activeDocument.
This should work. If not, kindly share the script you have in place.
Copy link to clipboard
Copied
var
myEventListener = app.eventListeners.item("TurnTCon");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener( "afterOpen", doJob );
myEventListener.name = "TurnTCon";
}
function doJob() {
var myDocument = app.activeDocument();
var myStory=myDocument.stories.everyItem();
myStory.trackChanges = true;
}
This is the Full Script. Its still doing the same thing. If i create a document from scratch Every story will have Track Changes enabled. But again if it is a file i created say 1 year ago and Track changes was never turned on for it the script does not turn it on.
Copy link to clipboard
Copied
I think your script is fine. I am wondering if any modal dialog gets opened when you open an existing document.
This script may fail if any modal dialog opens up when opening your old docs.
Do see any such modal dialog opening up?
Copy link to clipboard
Copied
They Some of the files I'm working with when i open them Have links that need updated. Could this cause the problem? If so can i add a delay to this code to wait till all documents are updated and fully loaded?
Copy link to clipboard
Copied
Possibly yes. Adding delay would not be the right solution.
Missing links is just one of such dialog. There could many be others like missing fonts, etc.
A more prudent approach is required. Check if there is a way to get into Preflight listeners after doc open.
Missing fonts, missing links, all would lead to preflight errors...
Will let you know if I can think of any other robust solution.
Copy link to clipboard
Copied
Please use the following code and let me know if all is well. I have made some modifications and explained below:
#targetengine session
var myEventListener = app.eventListeners.item("TurnTCon");
if (!myEventListener.isValid) {
myEventListener = app.addEventListener("afterOpen", doJob1 );
myEventListener.name = "TurnTCon";
}
function doJob(event) {
try{
if(event.parent.constructor.name == "Document") {
var myDocument = event.parent;
if(myDocument.stories.length > 0) {
var myStory = myDocument.stories.everyItem().trackChanges = true;
}
}
}catch(e) { }
}
Comments:
1. Better to include #targetengine session in first line of your script
2. The event "afterOpen" is triggered not only for documents but also for windows (layoutwindow, storywindow, etc.).
So, you have to filter out DocumentEvent only and proper error handling is required as I have done above.
Your previous code could have probably misinterpreted the activeDocument when responding to a Window's afterOpen event.
So, activeDocument does not suit in all places.
3. One of your line says: var myDocument = app.activeDocument(); A possible runtime error in your code.
It should be app.activeDocument as it is NOT a function. By the way, do not use activeDocument.
Consider the above code that gets rid of it.
4. The missing links dialog should not be an issue. I have checked it.
5. NOTE: Your document will always open as MODIFIED as you are making modification during opening of document (by turning on track changes). Hope you are getting my point here.
Copy link to clipboard
Copied
This works perfect. I had to change one thing. let me know if this is going to mess up the Script. I changed doJob1 to doJob because when i opened indesign without a file opened it gave me an error on line 6. When i deleted the 1 it fixed the error. I only got the error when i open indesign without a file opening right away. And thank you so much for your explanations. Yeah i know it will always open as modified. I'm more worried about seeing the changes that were made. And Seeing who saved it when it was last saved and Output( those are on a different script.
Copy link to clipboard
Copied
Oh, That was a typing mistake...it should be doJob and not doJob1 (line 6). There is no problem.
Copy link to clipboard
Copied
Ok thank you again for you work on this.
Copy link to clipboard
Copied
change the line 11 to
var myStory=myDocument.stories.everyItem();
so it will take all stories in the active document
Copy link to clipboard
Copied
Ok this is working. for the most part. Just one last thing on this one. When i create a new document it works just fine. But when i open an existing document it does not work. Is there an extra line i need to add to get this to work? Or since the other documents are already created is this just not possible?
Copy link to clipboard
Copied
Ah i was trying var myStory=myDocument.stories.Item(); thats why it would not work when i was doing it. Thank you so much.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now