Apply color to all tracked changes in Story Editor

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Apply color to all tracked changes in Story Editor

Viewing 25 reply threads
  • Author
    Posts
    • #93781

      Hello everyone!

      Is there any way/script to automatically apply a certain color to all the tracked changes in an InDesign document? This is mainly to be able to somehow track the changes (at least what was added) when exporting to .pdf.

      Or is there any GREP syntax that can search for all the tracked changes? If yes, this could be done automatically through the find/change option directly.

      Thank you very much!

    • #93861
      Peter Kahrel
      Participant

      Track changes isn’t exposed in the Find/Change window, but you can add a character style to additions with the following one-liner (first create a character style called change and set any formatting):

      app.documents[0].stories.everyItem().changes.everyItem().characters.everyItem().appliedCharacterStyle = app.documents[0].characterStyles.item(‘change’);

      Peter

    • #93870

      Thanks for the reply!

      Setting character styles is out of the question since most of the text will already have a character style applied to it, be it italic, bold or other (nested) combinations.

      Thank you again for your suggestion! Seems that only a complex script will solve the problem.

    • #93872
      Peter Kahrel
      Participant

      Doesn’t have to be complex (or even a script). You can apply some form of highlighting as a local override, e.g. underline.

    • #93873

      This is how I do it now. I typeset documents with lots of modifications that come from InCopy files, and I have to mark them in some way so the editor sees them in .pdfs. I make them magenta as a local override, but it takes a lot of time for 2000 pages books to go through each modification manually and set that color. (Open story mode, find next modification [Ctrl+Page Down], apply magenta. Repeat).

      That’s why I thought that if I can do that, a sort of script/macro could do it faster.

      Unfortunately colors can’t be assigned to a keyboard/mouse shortcut like para/char styles. I could work some macro on that.

    • #93875

      Alexandro, if you do it in your way, you highlight only additional and not removed text? If this is enough for you, conditions could also work:

      (function() { 
        var curDoc = app.activeDocument;
      
        if (!curDoc.conditions.itemByName("Highlight").isValid) {  
          var colorToHighlight = curDoc.conditions.add(
            {name:"Highlight",indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.YELLOW}
          );
        } 
        else {
          var colorToHighlight = curDoc.conditions.itemByName("Highlight");
        }
      
        curDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.SHOW_AND_PRINT_INDICATORS;
        curDoc.stories.everyItem().changes.everyItem().characters.everyItem().appliedConditions = [colorToHighlight];
      } () );
      

      Edit: It seems also possible to loop through all changes and different changes have a different type, e.g. changeType = DELETED_TEXT. So a more or less complex script could set a flag, draw a frame or whatever at this location or could even display the deleted text …

      Kai

    • #93877

      Hello Kai,

      you are indeed a master of your craft. I’ve been reading your posts for quite some time and you provide excellent scripts. Thank you for replying.

      Your sample script is almost too well done, because I can’t find a way to remove the yellow highlight if I want to. This is why I usually changed the font color from black to magenta, so the manual override could be reverted at any time with ease.

      In terms of what to track, the most important is the added text, since that’s what’s showing when the layout is done. If they want to check in depth I can always provide an InCopy .pdf that shows everything.

      But if it’s easier to script so it adds magenta to everything (deleted and added text) it’s no problem at all.

      Thank you again for your invaluable help!

    • #93878
      Peter Kahrel
      Participant

      Condition highlights don’t show in a PDF.

      If you want to apply a colour you can use this one-liner:

      app.documents[0].stories.everyItem().changes.everyItem().characters.everyItem().fillColor = app.documents[0].swatches.item(‘C=0 M=100 Y=0 K=0’);

      This uses the default colour ‘C=0 M=100 Y=0 K=0’ — make sure it’s there, or use any other colour.

      Peter

      • #93879

        > Condition highlights don’t show in a PDF.

        Peter, if the condition is applied to visible text and you use “ConditionIndicatorMode.SHOW_AND_PRINT_INDICATORS”, I can see here the hightlighting in a PDF.

        Kai

      • #93880

        Just exported a test .pdf with Kai’s script and it does export with the yellow highlight.

        Also, tried to run the one liner script, but it errors out. :(

        View post on imgur.com

    • #93881

      Alexandro, Peter gave you this one line for adding local Magenta.

      I think, the benefit of conditions are, that conditions are easier to control than local styling. Did you see the conditions-panel with the dropdown and those 3 options? If you want to remove the condition from special words, highlight the word and click on “unconditional”.

      Kai

    • #93882

      Alexandro, it seems, that for Peters version the quotation marks are messed up. This can happen during copy/paste > should be straight ones.

    • #93883
      Peter Kahrel
      Participant

      > if the condition is applied to visible text and you use “ConditionIndicatorMode.SHOW_AND_PRINT_INDICATORS”, I can see here the hightlighting in a PDF.

      Ok.

    • #93884

      Thank you so much to both of you. I now have two lucrative scripts that work excellent.

      I think I’m not the only one that needs this sort of stuff, so maybe an article on the website would make it more popular (or even come up with new ideas).

      Thank you again!

    • #93885

      Good to know, that both solutions are helpful :)

      It seems not to be possible, to add a shortcut to “Unconditional”. But we can script this command and give the script a shortcut:

      (function() { 
        var curSel = app.selection[0];
      
        if (!(curSel && curSel.hasOwnProperty ("baseline")) || curSel.constructor.name == "InsertionPoint") {
          alert("Select some text with a condition!");
          return;
        }
        if (curSel.appliedConditions.length > 0) {
          curSel.applyConditions([], true);
        }
      } () );
      
    • #93886

      Works as intended, although I think that usually after all the modifications are made they just select the whole text (Ctrl+A) and revert to normal color (which the script doesn’t seem to do). So they could just go to the Conditional text and delete the highlight from there.
      Thank you for the extra morsels! I think everything could be clumped together in a single script with dropdown choices too if you want to get fancy with it :)

    • #93888

      Alexandro, the last script is only for single words, if you want to exlude the highlight in the PDF. If you want to delete everything at the end, simply delete the condition. I have no desire for building a dialog with a dropdown at the moment ;-)

      While this seems to work for track changes, I can see another use case for conditions: marking words for an index. At the moment I’m working on a book with 250 pages and the author used a character style with magenta for highlighting words. Allthough I talked to him, only apply the style to words with black, he applied the style also to paras with gray or other color and messed up the complete document. So either use local styling or a condition.

    • #93889

      Indeed, this is why I avoid character styles altogether to highlight changes. They’re not for temporary stuff and it’s a hell to fix them, especially in books with lots of para and char styles.

      Using conditional text hasn’t really crossed my mind until now, and you are totally right: it can prove very useful and nondestructive.

      Although I am sad that they can’t have keyboard shortcuts. Dunno why Adobe restricted shortcuts to only a few ‘applicable’ characteristics of the text, like para, char and table styles. Would’ve loved to have some for Swatches or even conditional text (although the latter can be applied through quick apply).

    • #96235

      Hello everyone,

      coming back with an update regarding the scripts, which I have been using with some success for the past months.

      The only problem I encountered that I have no idea how to fix is that on bigger files, with (maybe) many changes made, when running the scripts (either Kai’s or Peter’s, using the latter most), InDesign just freezes. I’ve left if even 30 minutes to ‘do its thing’, but it just remains frozen, eating about 25% of the CPU power, like its doing something.

      Any ideas why this happens and if there is a workaround?

      I can’t thank you enough for the help!

    • #96236

      Hi Alexandro,

      InDesign has some problems with tracking and speed. I hear such freezing from the InCopy-corner. Peter and I use the everyItem() function. I would assume, that it could speed up things, when we use an array instead.

      Can you please provide a example with e.g. 50 or 100 track changes. It would then be possible to test both methods against a timer.

      Kai

    • #96237

      Thank you for the fast reply. Is there an e-mail where I can send you a file? I can’t really release them in the open…

    • #96238

      You can sent it to [email protected]. Please provide a idml, not indd.

    • #96239

      IDML file sent.

    • #96240

      Some interesting stuff!

      Alex has about 1200 conditions on 70 pages. With the line from Peter

      app.documents[0].stories.everyItem().changes.everyItem().characters.everyItem().appliedCharacterStyle = app.documents[0].characterStyles.item(‘change’);
      

      there is no result and I crashed InDesign after 15 minutes.

      var curDate  = new Date();
      var oldStamp = curDate.getTime();
      
      var allChanges =app.documents[0].stories.everyItem().changes.everyItem().getElements();
      var nChanges = allChanges.length;
      
      for (var i = 0; i < nChanges; i++) {
        var curChange = allChanges[i];
        var nCharacters = curChange.characters.length;
        if (curChange.changeType == ChangeTypes.INSERTED_TEXT) {
          for (var j = 0; j < nCharacters; j++) {
            curChange.characters[j].fillColor = "Magenta";
          }
        }
      }
      
      var curDate  = new Date();
      var curStamp = curDate.getTime();
      var difSec   = (curStamp-oldStamp)/1000;
      alert (difSec);
      

      122 seconds

      var curDate  = new Date();
      var oldStamp = curDate.getTime();
      
      var allChanges =app.documents[0].stories.everyItem().changes.everyItem().getElements();
      var nChanges = allChanges.length;
      
      for (var i = 0; i < nChanges; i++) {
        if (allChanges[i].changeType == ChangeTypes.INSERTED_TEXT) {
          allChanges[i].characters.everyItem().fillColor = "C=0 M=100 Y=0 K=0";
        }
      }
      
      var curDate  = new Date();
      var curStamp = curDate.getTime();
      var difSec   = (curStamp-oldStamp)/1000;
      alert (difSec);
      

      30 seconds!

      So it seems, that a combination of everyItem() AND getElements() + counting the length of something outside the for-loop is much faster.

      Kai

    • #96241

      I can only thank Kai again for his amazing help. All that he did is sorcery to me, but it works flawlessly. I hope this script will prove useful for anyone else that wants to put their time in the actual design process of the layout, rather than wasting it with boring (but sometimes necessary) tasks.

    • #14356601

      Help with tables wanted: How to color/underline all text changes in tables?

      Found this page and use the script. It is working very well for underlining all the tracked text changes in Indesign 2022.
      This is working great for regular text, but not for text in tables. And I work with financial reports filled with tables.

      How to color/underline all text changes in the tables?

      Would be great if this can be resolved.

      Sibren

    • #14356783

      This is solved by Brian Pifer of designtimesolutions.com

      I changed the first line to:

      var allChanges = app.documents[0].stories.everyItem().tables.everyItem().changes.everyItem().getElements();

      • #14356784
        David Blatner
        Keymaster

        Awesome! Thanks for coming and letting us know, Sibren.

    • #14394832
      Steven Grey
      Participant

      Sorry. This is a very basic question. How do you actually use these? Are they saved as text files with the jsx extension and added to the scripts panel (that gave me an error)?

Viewing 25 reply threads
  • You must be logged in to reply to this topic.
>