[JS][CS2]Find/Change loop

Hello Scripters,
I need to find a specific character style in my document then process its content and replace it with the processed content. How can i make a loop so that it process all of the instances of that style?
To make the picture clearer, let's say I'm gonna search for all the superscripted then let's say remove the commas in it and sort it.
i got it right but it only replace the first intance. how can i make a loop so it process all the instances of that character style.
app.findPreferences.appliedCharacterstyle = 'mySup';
var mySearch = app.activeDocument.search('');
for (i=0; i>mySearch.length; i++)
var myResult = myFunction();
app.activeDocument.search( "whatDoIPutHere?", false, false, myResult );
help please...

You have got the wrong idea about the Search function. It finds *everything*, and it returns an array of all found items. You don't have to search again.
With that out of the way :-) if your function 'myFunction' does something to the text that changes its length (you mention removing comma's), the array of found items is no longer valid, because it points to character indexes from the start of the document. (I guess.) The advocated way of handling this is to start processing at the
b end
of the 'found' array, so any manipulations will not mess up the rest. I.e.,
for (i=mySearch.length-1; i >=0; i--)
    var myResult = myFunction();

Similar Messages

  • Finished script: Use grep find/change to fill in a supplied table of contents

    This script is now complete, and has been the subject of most of my previous posts. Just in case anyone wanted to know what the finished script ended as, here it is.
    Thanks so much to all. A lot of really helpful folks on this board are very responsible for the success of this task. This script is to be one of hopefully many in the creation of our records. But it's a huge leap forward. Thanks again to everyone that helped.
    Cheers,
    ~Nate
    Task:
    Automatically find town names in listings, and fill in table of contents template on page 2 accordingly.
    Example of page 2 toc, initially:
    Example of a page of content. The town names are what need to be referenced on the TOC:
    Example of page 2 toc once script is finished:
    Because of the need to include the transaction dates on the TOC (comes as a provided, tagged-text file), a simple Indesign-generated TOC can't be used alone.
    This script uses an Indesign-generated TOC that's on a master page called "T-tocGen" ... It then uses grep search and replaces to grab the needed information, and insert it into the page 2 TOC.
    The script will update a generated TOC and then search for an instance of a page number, and town name. The generated toc lists all included towns in the following format:
    (line start)## tab townName(line end)
    In Grep, this would be (please note, extra \ for \d and \t ... javascript needs that for some reason):
    ^\\d+\\t(.*)$
    After the script gets the info it needs from a found instance of the above, it replaces that line with "---", to prevent that line from being picked up once again.
    The script with then place the needed page number in it's rightful place on page 2, replacing the XX.
    A while loop is used to repeat the above process until there are no longer any instances of "^\\d+\\t(.*)$" present.
    Not every town runs every issue, so once the script is done, it removes all remaining instance of "XX" on the page 2 TOC.
    FINAL CODE:
    TOC replace
    This script will use grep find/change methods to apply page numbers in
    tocGen to the XX's on page2TOC.
    // define the text frame of generated TOC
        var tocGenFrame  = document.masterSpreads.item("T-tocGen").pages.item(0).textFrames.item(0);
    // udpate generated TOC ... store contents in tocGenStuff
        var tocGenStuff = updateTOCGen();
    // set variable for while loop
    var okGo = "1";
    // while okGo isn't 0
    while(okGo.length!=0)
    // get town info from tocGen
    getCurrentTown();
    // replace XX's with tocGen info
    replaceTown();
    // grep find ... any remaining towns with page numbers in tocGen?
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "^\\d+\\t(.*)$";
    // set current value of okGo ... with any instances of above grep find in tocGen
    okGo = tocGenFrame.findGrep();   
    // grep find/change all leftover XXs in page2TOC
    app.findGrepPreferences = app.changeGrepPreferences = null;       
    app.findGrepPreferences.findWhat = "^XX\\t";
    app.changeGrepPreferences.changeTo = "\\t";
    app.activeDocument.changeGrep();  
    // clear grep prefs
    app.findGrepPreferences = app.changeGrepPreferences = null;
    //  functions                  //
    function getCurrentTown()
    // grep options   
    app.findChangeGrepOptions.includeLockedLayersForFind = true;
    app.findChangeGrepOptions.includeLockedStoriesForFind = true;
    app.findChangeGrepOptions.includeHiddenLayers = true;
    app.findChangeGrepOptions.includeMasterPages = true;
    app.findChangeGrepOptions.includeFootnotes = true;
    // grep find:  startLine anyDigits tab anyCharacters endLine
          app.findGrepPreferences = app.changeGrepPreferences = null;
          app.findGrepPreferences.findWhat = "^\\d+\\t(.*)$";
    // get grep find results      
    currentGen = tocGenFrame.findGrep();  
    // store grep results content into currentLine
    currentLine = currentGen[0].contents;
    // match to get array of grep found items
    currentMatch = currentGen[0].contents.match("^\\d+\\t(.*)$");
    // second found item is town name, store as currentTown
    currentTown = currentMatch[1];
    // change current line to --- now that data has been grabbed
    // this is because loop will continue as long as the above grep find yields a result
           app.findGrepPreferences.findWhat = "^\\d+\\t"+currentTown+"$";
                  app.changeGrepPreferences.changeTo = "---";
                tocGenFrame.changeGrep(); 
    function replaceTown()
    app.findChangeGrepOptions.includeLockedLayersForFind = true;
    app.findChangeGrepOptions.includeLockedStoriesForFind = true;
    app.findChangeGrepOptions.includeHiddenLayers = true;
    app.findChangeGrepOptions.includeMasterPages = true;
    app.findChangeGrepOptions.includeFootnotes = true;
    // find: XX currentTown .... replace with: currentLine
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = "^XX\\t"+currentTown+" \\(";
        app.changeGrepPreferences.changeTo = currentLine+" \(";
    app.activeDocument.changeGrep();   
    function updateTOCGen()
    //set vars ... toc text frame, toc master pag
        var tocGen  = document.masterSpreads.item("T-tocGen").pages.item(0).textFrames.item(0);
        var tocGenPage  = document.masterSpreads.item("T-tocGen").pages.item(0);
    //SELECT the text frame generatedTOC on the master TOC
        tocGen.select();
    //Update Table of Contents by script menu action:
        app.scriptMenuActions.itemByID(71442).invoke();
    //Deselect selection of text frame holding your TOC:
        app.select(null);
    //store contents of toc text frame in variable
        var tocGenText = tocGen.contents;
    //return contents of tocGen
        return tocGenText;

    Thanks for the reply.
    You are correct but the problem is there are three rows, One row is 100% black, the second is 60% black and the third is 40% black. I want to change the black to blue, the 60% black to an orange and the 40% black to a light shaded blue. In the find/change option you can select the tint you want to find and replace but yea.. does work on table cells.. oddly enough.

  • [CS3 JS] Find/Change Object Problem

    app.changeObjectPreferences = NothingEnum.nothing does not seem to clear the change object preferences for me.
    app.findObjectPreferences = NothingEnum.nothing works as expected, as do both app.findTextPreferences = NothingEnum.nothing and app.changeTextPreferences = NothingEnum.nothing.
    Does anyone else use the new Find/Change Object?

    Hello. I'm new here but it seems to be the only place where I can post this question to.
    I'm working in a C# application that uses InDesign CS3 scripting. I'm trying to create an index automatically from a tabbed list of words in a text file.
    As C# is a strongly typed language, I have to cast all objects to the right type. I'm having problems when I try to add the page numbers to the created index entries using the following code (I've used the CreateIndexEntry.jsx scrip as a starting point).
    //Find all occurrences of the word or set of words (the topic name)
    ((InDesign.FindTextPreference) app.FindTextPreferences).FindWhat = topic.Name;
    InDesign.Objects foundTexts = doc.FindText(System.Reflection.Missing.Value);
    It's supposed to be an Array of Text objects (InDesign.Text) but when I try to cast each object using this
    //Code is forced because I've tried everything here
    //Loop through each finding and add page numbers to topic
    IEnumerator textEnum = foundTexts.GetEnumerator();
    while (textEnum.MoveNext())
    object text = textEnum.Current;
    topic.PageReferences.Add((InDesign.Text)text, InDesign.idPageReferenceType.idCurrentPage, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
    I got the following exception (translated).
    text is not an InDesign.Text object (Interfaces doesn't match)
    So the question is what object type should I use to cast each object resulting by calling the Document's FindText method.
    Every suggestion will ve very welcome.
    Thank You very much.

  • JS for Find/Change

    I am a novice with JS, but trying to make a couple of enhancements to workflow using scripting. I have managed to figure most things out ok, but usually just need a little kickstart. What I am trying to do is:
    InDesign CS2
    Find a specific sequence of characters in a text selection (in this case, " - " (that is space dash space) and replace with end of nested style & forced line break (^h^n). At the same time, search for double carriage returns and change to single carriage returns (^p^p => ^p).
    Currently, using the Find/Change Function from the Edit menu but I'd like to be able to just apply a script to do it all. I have tried to dig through the archives for a similar posting, but haven't had a lot of luck. If anyone can please point me in the right direction, it would most certainly be greatly appreciated!
    Thank you in advance.
    -Scott

    Thank you Peter ... I have just purchased the electronic version of the O'Reilly book that you recommend. This will certainly help.
    One thing that is not clear ... can I use characters such as "^p" or "^h" directly when setting my parameters, or is there a unicode equivalent that I would need to use?
    Thanks again.
    -Scott

  • Find/Change whole words in CS3

    Maybe I'm just being dense, but when I do a find/change in ID CS3 I can't find the option to search for whole words only. The default is set to ignore whole words, so I end up finding a lot of undesirable matches. My last search was for "air," so you can imagine how many false matches I got.
    This was quite obvious in CS2, but those options (including match case) seem to have moved somewhere where I can't find them.
    Any assistance would be most appreciated.
    Mark

    With your mouse, examine each of the icons under the Change field. A tooltip identifies each one. One of them is the one you want.
    Dave

  • Find/Change Item Numbers and create Table of Contents

    Hello! I need help to find all my item numbers and apply a paragraph style to it so I can use them to create a Table of Contents page.
    Sample item numbers
    #12345
    #12345-5
    #12345-20
    #12345-ABC
    #12345/N
    I tried entering #^?^?^?^?^? on the Find/Change box and but this will find exactly the 5 characters after the # sign. I wonder if you can find all characters starting with # and until the last characters.
    Once I find all the item numbers, how can I apply the paragraph style for only those characters after the # sign? Because I only want to show the item numbers without the # sign on the Table of contents/Index page.
    By the way, I have InDesign CS2 which have no GREP function Maybe I can do this without the GREP?
    I really appreciate any help. Thank you very much.

    You actually have two problems here. The first is to assign the paragraph style. For that you can use GREP.
    Find #\d+ and leave the change field blank, but in the change formatting pick the paragraph style. Stricly speaking you only need to find #\d or even just # because a paragraph style applies to an entire paragraph, so assigning it to any character inthe paragraph will assign it to the entire paragraph.
    Which is your second problem. The TOC is based on paragraph styles and will include all of the text in each paragraph (up to the character limit for a TOC entry, which I think is 256 characters). You can't make a TOC and only use some of the paragraph. For that you need to use an index, or you need to make hidden or non-pinting frames with only the exact text you want in the TOC and assign a unique style to those.
    It's also possible someone has written (or could write) a script that can find text strings that match a pattern such as your numers, assign a character style to them (you could actually do that part in the paragraph style by adding a nested GREP style), then making a list of the text strings along with the page number on which they appear -- almost the same as an index except it would be based on character style, not an index marker.

  • How to find Change number for a Material

    Hi,
    If we know the material number and Revision level then how can we find the Change Number of that material.
    Is there any table in which i can find Change number for a revision level or is there any Function module available.
    Regards,
    Vaibhav

    Hi Vaibhav,
    Is there any table to find the change number and revision level of a material. I have change number and material and revision level coming from external system. But i need to check that with SAP whether it exists or not.
    Is there any table link to find whether a material has change number.

  • Find Change through external text file

    Hello folks
    I am bit pretty in InDesign scripting so could you please look into this.
    How can i change any particular text field in Indesign CS3 document from text file.
    I do have find change script but for each InDesign document specific text file is assigned.
    So each time i have to modify find change GREP property that is also repetetive of work. Is there any way to get find change information should be extract from external text file.
    Many Tanks in advance

    In the FindChangeByList script, you could customize the function myFindFile(myFilePath) {...} as to search the FindChangeList text file in the document location rather than the script location. That's an example. The question is: given a document, where will you have the corresponding FindChangeList?
    @+
    Marc

  • How to Open Find/Change with menuAction

    Hi,
    Read the question carefully I'm asking how to open the Find/Change
    dialog, not how to toggle it.
    Toggling is easy enough:
    app.menuActions.itemByName("$ID/Find/Change...").invoke();
    But if it is open, this will close it, and vice versa.
    I'm wondering if there's any way to specifically make sure it's opened?
    Thanks,
    Ariel

    Hi Ariel,
    This probably won't help but see https://forums.adobe.com/message/4413557#4413557
    If you could perform some action that will fail if the panel is closed then you could use a try catch to determine its state.
    I'll leave it to you to think of what that action would be.
    Trevor

  • FrameMaker 8 (Unstructured) - How to Find/Change "Referenced File" location globally?

    Hello,
    First off, I have a FrameMaker 8 (Unstructured) book that links ALL of its graphics, to a separate graphics folder on my network drive.
    With that said, I am hoping to do the following:
    1. Create a mirror copy of "Book A" and place that copy in another folder, (at the same level) on my network drive.
    2. Open up the new book file (e.g. Book B).
    3. Run a Find/Change to replace:
    ..\..\..\Graphics Catalog A\Graphics\a000123.png
    ..\..\..\Graphics Catalog B\Graphics\b000123.png
    The end result is that I could globally map out all the "Referenced Files" to the new folder path structure. This will allow me to save from having to manually re-import each of the 1000 graphics - into my book files.
    Finally, I am hoping to do this with the built in capabilities of FrameMaker 8 first. If that is not possible, then I will consider other possibilities.
    Thanks in advance for any suggestions.
    Regards,
    Jim

    This is how you do it:
    Outside of FM, copy the "Book A" folder and paste it where you want.
    Also, create the Graphics folder and file structure (i.e.
    "... Graphics Catalog B\Graphics ...")
    Before you open Book B in FM, temporarily rename the graphics
    folder that the FM files in Book A uses, e.g. "Graphics Catalog Z".
    Now, when you open the files in Book B, FM won't be able to find
    the old graphics since the folder name has changed. For each file,
    FM will open the "Missing graphics" dialog, where you need to
    browse to the new graphics folder, e.g. "Graphics Catalog B\Graphics".
    Select the correct file that FM asks for, and tick the option to
    use this folder for all remaining graphics.
    If all the image file names are identical, you will only need to
    do this once per FM file. If you really need the image file names
    to differ like you said:
    > ..\..\..\Graphics Catalog A\Graphics\a000123.png
    > ..\..\..\Graphics Catalog B\Graphics\b000123.png
    then you need to select the correct file name for *each* graphics
    that FM cannot find. This is a good reason to keep the file names
    identical, even though the folder name has changed.
    When all the files have opened, rename the original graphics folder
    back to "Graphics Catalog A".
    /Thomas Michanek

  • How do I make a script to find/change many in one go

    I have a long list of words that I do a find/change to avoid breaks and keep with the next word. Words like Dr. Mr. Mrs. :
    Is there an easy way to put all the words and symbols that I want to change into one script to save doing each one at a time?

    1) Free solution: FindChangeByList.jsx
    (in \Scripts\Scripts Panel\Samples\JavaScript)
    2) Better and very flexible solution: Multi-Find/Change
    http://www.automatication.com/index.php?id=12
    @+
    Marc

  • [JS CS3] Find/Change "[Basic Paragraph]" style

    I'm trying to find all occurances of the [Basic Paragraph] style and replace them with [No Paragraph Style]. I'm using:
    app.findTextPreferences.appliedParagraphStyle = "[Basic Paragraph Style]";
    app.changeTextPreferences.appliedParagraphStyle = "[No Paragraph Style]";
    I get the message "Invalid value for set property 'appliedParagraphStyle'. Expected String, ParagraphStyle or NothingEnum enumerator, but received "[Basic Paragraph Style]"."
    I've tried every combination of brackets, no brackets, quotes, no quotes, etc. It doesn't seem like this can be scripted, even though it can be done via find/change in InDesign. Am I banging my head against the wall? Does anyone know if this can be done?

    "[Basic Paragraph]" as shown in the code below doesn't work either. (the word "Style" actually snuck in as I was trying different variations. But no combination seems to work.
    If anyone knows that [Basic Paragraph] can or cannot be accessed via scripting, I'd like to know. Thanks.
    app.findTextPreferences.appliedParagraphStyle = "[Basic Paragraph]";
    app.changeTextPreferences.appliedParagraphStyle = "[No Paragraph Style]";

  • Find/change using end of paragraph marker /p

    Folks,
    We are attempting to remove a space at the end of a paragraph in unstructured documents.  If I enter ' \p' in the Find text field in the Find/Change dialog FrameMaker finds the the appropriate paragraphs.  If I then enter '\p' in the Change text field in the Find/Change dialog and click Change the space is removed.  However the target paragraphs style is also applied to the the following paragraph.  This occurs in FrameMaker 8,9 & 10.
    If the Find/Change scenario above is followed with these two paragraphs the first paragraphs style is applied to the second paragraph.
    paragraph 1 with a trailing space and using Heading 1 style
    paragraph 2 using Heading 2 style
    Any thoughts?
    regards
    Jon

    JonEBe wrote:
    Arnis,
    Thanks!
    Yes why bother indeed!  I am at the end of a rather lengthy process to convert the creation and output of Framemaker documents into a database with a web front end.  As part of this the existing documents are imported to save lengthy keying/rekeying.  The output from the system is then compared against the originals.  As a matter of course I stripped of leading or trailing spaces (it is amazing how many there are in a manually created/updated document) so we therefore have noisy comparison documents as a result.
    BTW the trailing spaces are apparently a legacy of the conversion from WordPerfect.
    My choices are to re-import without stripping the trailing space and remove them at a later date or create a script using the FDK, which I am very familiar with, and is the likely outcome!
    Jon
    Just a wild thought - a real GREP processor, not the mild imitation in FrameMaker, can find a construction like a space followed by a paragraph marker and delete the space without affecting the marker. The technique is a form of the "lookbehind" or "lookahead" feature. I'm zero-skilled at actually doing this beyond just mentioning it, but the technique might work in a MIF, or text conversion, of the file. Search Google for terms like "GREP lookbehind lookahead," without quotes.
    Another possibility is that once the FrameMaker file is converted to the database, it would be possible to use a database command to remove the space.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • How to use Find Change to add FC in front of all item numbers?

    Hello,
    I am using Indesign CS5 on iMac, running OS 10.8.3.
    I designed a product catalog that has 148 pages. Now I need to save the same design and make a new catalog for our wholesalers. On the wholesalers catalog I need to change the item numbers and add FC in front of each item number. How can I use find change to find each item and change them with FC in front of the item numbers? The following are a few examples of the item numbers:
    LED-4042 I want to change it to FCLED-4042
    UA-42 I want to change it to FCUA-42
    SC-110 change it to FCSC-110
    KN-10 change it to FCKN-10
    etc....
    I am hoping there is a fast way to find and change these.  I was looking in to GREP, but I could not figure how to do this.
    Thanks,
    Omar

    One way would be to just run it and then *remove* any double FC's -- but GREP can do even more! One of its many functions is to scan ahead for the presence or absence of certain text, and only act when it is (or it is not) there. This is called "lookbehind" (before the text you want to match) and "lookahead" (after the text you want to match).
    In this case, you want to find a phrase starting with capitals, but NOT the exact string "FC". That's a job for Negative Lookahead -- Only Match If Not.
    Try this: search for
    \b(?!FC)\u+-\d+\b
    ... the Replace With stays the same.

  • GREP 'find/change' by list script: find a text string containing different para styles

    Hi
    I'm don't write scripts but do 'enjoy' copying, pasting and changing existing code/txt files.
    I have built a GREP find/change .txt that performs a large number of text edits/changes.
    But I'm left with an issue where I have paragraphs of text (styled earlier in the .txt file) that I'm unable to identify using GREP the usual way. I need to identify text in a particular paragraph style, followed by text in another paragraph style.
    Is it possible with GREP to create a search string to find: text styled with one paragraph style, ending with a paragraph return, and to include in that selection the following paragraph/s styled with another paragraph style?
    MTIA Steve

    seb400 napisał(-a):
    What do you mean by I would mark "changing" in "copying, pasting and changing"?
    Hi Steve,
    I mean I can see a way by modifying some existing code with "find...change" job
    1. set criteria to findGrep
    2. store findGrep() in an array
    3. check each found object if next paragraph matches some new criteria
    4. run changeGrep() if true
    Jarek

Maybe you are looking for

  • Distortion when connecting iBook to Sony Projector

    I have an iBook G4, 1Ghz, 10.4.11, 1.25GB RAM, Keynote '08 When I connect the iBook to any TV using composite, S-video, or 15-pin VGA I get a crystal clear picture. But when I use it at work with a Sony VPL-CX86 projector the picture is distorted on

  • MSI GTX 970 4G making unhealthy noises

    I've recently upgraded my computer a bit, and recently my graphics card has been making some rather unhealthy-sounding high-pitched whining noises whenever I play games. It's definitely not the fans, because I checked with my case part-open to listen

  • Error:INF

    Post Author: Hennie CA Forum: Deployment Hi, I just installed BO XI Release 2 on a server of a client. They have BO XI R2 running on another server, but due to disk restrictions on that server we need to reload it. We've exported all the databases fo

  • SignalExpress 2010 - Chart time axis format will not change to floating point or anything else

    I just downloaded and installed the new and shiny SignalExpress 2010 to replace the old version. And immediately run into major problems: The x-axis time format refuses to change to floating point or scientific even if I choose them from chart proper

  • IPhoto storage management on iPad

    The iPad storage is quickly filled up with photos and journals. Is there a way to store iPhoto journals on iCloud only to free up space on my iPad?