Find/replace, highlight found text script

Hello

I wrote this script and it works fine. But what I want to do is to go through each word found individually (as in the Find/Replace dialog box with the button "find next").

This is an excerpt:

app.findTextPreferences = app.changeTextPreferences = null;
var what = app.findTextPreferences.findWhat = "ensure";

app.changeTextPreferences.changeTo = "make" sure;
var found = app.activeDocument.changeText ();
If {(found.length = 1)
Alert (found.length + "instance of"ensuring"changed");
} else {}
Alert (found.length + "instances of"ensuring"changed");
}

I want the script to each instance of "ensure" my active selection that I can see where they are before I change.

Thank you

Hi guys,.

try this one:

app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = "ensure";
app.changeTextPreferences.changeTo = "make sure";

var allFounds = app.activeDocument.findText();
for (var i = 0; i < allFounds.length; i++) {
  var curFound = allFounds[i];
  curFound.select();
  app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;
   if(confirm("Do you wish to change this instance?",undefined, "Find/Replace")) {
     curFound.changeText();
  }
}

app.findTextPreferences = app.changeTextPreferences = null;

Disadvantage of the confirm dialog box: there is no exit button.

Tags: InDesign

Similar Questions

  • Find/replace highlights the bad code

    Hi, if you use find it normal and the search for specific text in my AS3 class file, it highlights the right position where he finds corresponding text, but when I use the search/replace completely it messes up, it highlights the text wrong in my code, but it displays the correct position in the Find/Replace window. Is there a way to fix this, or is this a known bug? See attached screenshot.

    Screen Shot 2013-06-19 at 10.56.15 PM.png

    Hello

    Thanks for sharing the file.

    The problem is with the end of Line (EOL) character. The file uses a rating of CR at the end of his LIFE and has been used in Mac OS 9 and Mac OS 9 version. When a file is created using one of these versions of Mac OS and then the EOL character would be CR which is now obsolete and is not recognized by many modern text editors.

    If the EOL is LF or CR | LF then search and replace will work as expected in Flash CC.

    You can change the end of LIFE of the file to open and save the file in Wordpad that will change the EOL to CR | LF.

    Hope this information helps you solve your problem.

    Thank you!

    Mohan

  • Acrobat 9 search feature needs to highlight found text

    Search existing documents for use of the word "results" sometimes in the updated Word highlight and sometimes only the cursor is placed on the word found with no nails. This is a problem because that tcursor it is very difficult to locate without highlight.

    The "Search" function should ensure that the found text is still selected.

    Or maybe there is a setting for this?

    (Also still waiting for a display display/Page default to 'Two Up continuous' as it constantly on a single Page, which is a waste of large monitors by default.)

    Thank you.

    This bug has been corrected in Acrobat 9.4.6 update:

    Windows:

    http://www.Adobe.com/support/downloads/detail.jsp?ftpID=5244

    Mac:

    http://www.Adobe.com/support/downloads/detail.jsp?ftpID=5238

  • object contains no text for find/replace

    I am trying to run this script to select text if it is found, but he said that there is no text, even though I have wrapped them in an if statement.

    See section function () {}

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "the (section\\s +?). \\d+ ? [ \\.\\d+]?)";

    app.changeGrepPreferences.changeTo = "$1";

    The app.changeGrepPreferences reference .appliedCharacterStyle = "cross";

    If (app.activeDocument.findText ()) {}

    found. Select();

    };

    var changes1 = app.activeDocument.changeGrep ();

    If {(changes1.length===1)}

    Alert (changes1.length + "instance of 'the section' became 'article'.");

    } else {}

    Alert (changes1.length + "instances of 'the section' changed to 'section'.");

    }

    };

    Your message to find/replace script highlight found text is not the same question?

  • Moving a text box automatically using find/replace?

    I have a text box containing the given text (for example "Hello-hello12"), through several separate documents. I want to move this text box make a different location on the page of all these documents. Is it possible to do in bulk? I looked in the search/replace option, but could not find a way to do over there. I use CS6 if it matters.

    Thank you!

    It does however find/replace, but maybe the script though. Ask above in InDesign Scripting

  • How find/replace just a story of VB script.

    Hi all

    I use a lot of find/change grep options in my VB script. But find/replace replace always in each textframe I have on my current document. I would like to define just to do this on a story (which would be on the selected text blocks). Can anyone help? I try to find that in virtue of
    FindChangeGrepOption, but I see this is not the place. I have attached the screenshot so you can see what I set in my VB script.

    Thank you.

    The trick is to target the research of history of interest. In JavaScript, I would write something like this (with the first installation the find/replace):

    myStory.changeGrep ();

    Dave

  • Need help with this find/replace Script.

    Hi I got this script from Loic.Aigon.  And I got it works for find/replace simple changes however I Cannon operate for several changes.

     function cb5CallBack(target) {
            var findProps, changeProps;
            
                findProps = {findWhat:"Distributed by ",}   
                  changeProps = { changeTo:"Distributed by. ",}
                findProps = {findWhat:"Distribué par ",}   
                  changeProps = { changeTo:"Distribué par. ",}
                findProps = {findWhat:"Distribuido por ",}    
                  changeProps = { changeTo:"Distribuido por. ",},
              
            RTXT(target, findProps, changeProps);   
            } 
    

    function RTXT(target, findProps, changeProps)
    {
    app.findChangeTextOptions.caseSensitive = true;
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.properties = findProps;
    app.changeTextPreferences.properties = changeProps;
    app.changeTextPreferences.properties = changeProps;
    target.changeText();
    }
    

    You must call the function RTXT repeatedly as well:

        var findProps, changeProps;

        findProps   = { findWhat:"Distributed by "};

        changeProps = { changeTo:"Distributed by. "};

        RTXT(target, findProps, changeProps);

        findProps   = { findWhat:"Distribué par "};

        changeProps = { changeTo:"Distribué par. "};

        RTXT(target, findProps, changeProps);

        findProps   = { findWhat:"Distribuido por "};

        changeProps = { changeTo:"Distribuido por. "};

        RTXT(target, findProps, changeProps);

  • conditional text find/replace problem

    Hello!

    For a few hours, I'm trying to solve this case: I want to apply conditions (conditional text) to all paragraphs according to the name of the applied style. So, for example, text with paragraph called "BODY" style should have "BODY" of the conditional text etc. I figured out mechanism, but I can't solve the problem with passing to find/replace.

    Here is my code:

    (function() {
        if (app.documents.length > 0) {
            processDocument(app.documents[0]);
        }
        function processDocument(aDoc) {
            var paraStyles = aDoc.allParagraphStyles.sort();
            for (var j = 0; paraStyles.length > j; j++) {
                var currentStyle = paraStyles[j].name;
                if(aDoc.conditions.item (currentStyle) == null){
                    var varConditions = aDoc.conditions.add({name: currentStyle});
                }
                doFindChange(currentStyle);
            }
        }
    }())
    function doFindChange(currentStyle) {
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
        
        app.findGrepPreferences.appliedParagraphStyle = currentStyle;
        app.changeGrepPreferences.appliedConditions = currentStyle;
        
        app.activeDocument.changeGrep();
    }
    

    I know what's wrong, but I have no idea how to change.

    Could someone help me?

    Thanks in advance!

    You have some problems in the code:

    1 move the actual paragraph style (and not just its name) to findGrepPreferences (your variable, currentStyle is a string, although this can work, it is better [especially for paragraph in the groups styles] to adopt the paragraph style real itself).

    2. Ditto for the appliedCondition: give changeGrepPreferences the condition itself, not just its name.

    3. it seems that changeGrepPreferences.appliedConditions expects a range of disorders, then give him a table even if it has only one member.

    Ariel

  • DC as a sentence installed and I can't find anything! How do I highlight some text in the box, how can I change the text color?

    DC as a sentence installed and I can't find anything! How do I highlight some text in the box, how can I change the text color?

    Hi taraf32044550,

    I think the new user interface can be a bit of a learning curve, but I hope that you really like it when you find your bearings. Please check these tutorials will help you to find your way around: Acrobat DC Learn & support.

    In particular, I think that you will find this tutorial very useful: change text and images in PDF files

    Best,

    Sara

  • Find/replace for text formatting

    Hi guys,.

    How to use find/replace for text formatting changes? I would like to change a text of entire book to try an another typographical options. The book is currently typed in text of Lyon. The problem is when I change to Sabon will make it overides the italics and the word "BOLD".

    I tried to find/display

    Search

    Lyon text regular italic

    Change

    Sabon italic

    Captura de pantalla 2015-02-18 a la(s) 10.17.19.png

    but it does not work. Most of the text of this book is not formatted with the character to italic Style, for example, just a paragraph Style General to make it easier to work with.

    What I am doing wrong? Any help or ideas?


    Thank you!

    All of the text has a paragraph style that applies the formatting of basis for the whole paragraph. ALL text that deviates from the General formatting of the paragraph should have a style of character applied somehow, either directly, or as a nested or style GREP, which overrides the formatting of paragraph and gives what you want. The paragraph styles that do not change the font family are much more useful, for example a style that just changing the text in italics, as they continue to work when you change the font family of the paragraph style in the basic text format section.

    Character styles are used ONLY to change the part of the text in a paragraph. If the paragraph has the same formatting, it should have a paragraph set for this format style.

  • find a block of text on the page with the name of script

    Hi all

    I need to create a script for

    find a block of text on the page with the script titled "xxx".

    and read its contents into a variable.

    The content of the text block is a number.

    Thank you

    Hello Roberto,

    Welcome to the forum,

    This is the textFrame marked on the current page.

    var myLabel = "Foo", // change to label
          myPage = app.properties.activeWindow && app.activeWindow.activePage,
          myTextFrames = myPage.textFrames.everyItem().getElements().slice(0),
          l = myTextFrames.length,
          myVariable
    
    while (l--) {
        if (myTextFrames[l].label != myLabel) continue;
        myVariable = myTextFrames[l].contents;
        break; // presuming there's only one "Foo" labeled frame on the page
        // Otherwise you'll nead an array
        }
    
    alert(myVariable)
    

    Trevor

  • Find + replace text (string constant) does not work for screw Statechart module

    Hello

    I tried to do a mass find + replace a string in my code. Using Ctrl + F, LabVIEW 2012 correctly locates all the places where this string exists, including within the States transitions guards who have paths in this form:

    XYZ.lvsciagram.vi / Transition: Guard - diagram, Transition, data/part

    However, when I've specified that a replacement string, then click on 'Replace all', only 'normal' instances of screws replaced - instances in my diagrams had not changed.

    What is going on? Is there anything else I need to do?

    Thanks in advance.

    Looks like those that does not include how to find and replace is implemented in LabVIEW. You can try to replace just the statechart and see if that makes a difference, but it may simply not work.

  • GREP find/replace + paragraph Styles

    Hello

    I'm editing a long document and have benefited from the assistance of the community already, but being new GREP Style, find/replace, I need to ask for additional help.

    Below a screenshot of the script (original). Two blocks of text you see anticipated by the icons have have styles of different paragraphs. Icons are placed like custom glyphs.

    Now, the last line with C2, 9, 14,... is the target of this post. They are buses of London and I created a paragraph with another icon. The copy that I work with unfortunately is as you see. Buses will follow «;»

    Resulting to place a \r after the semicolon and assign the new paragraph style. The item to work with is (probably) the last "," before the registration of the bus. All entries have it in the same way, where a search/replace global grep should work fine.

    My attempts:

    I used of a previous debate (? < =------;)) [^ ;] + $ to match everything from the end until the last semicolon, but then I found the problem preserving the matched characters and placing \r (using the (? < =-;). start at the beginning and stops at each point comma + space)

    So question: how to stop at the first semicolon at the end and replace the space with \r to create a new paragraph?

    Then, it is two question :-)

    From my previous attempts, I noticed that when you replace the semicolon + space with \r, and change the style of paragraph at a time (from Rail to Bus) caused the Rail paragraph style change (logic) to the style of Bus. So I tried to say the paragraph style of the track "Following paragraph Style is style of Bus" (and not to change the paragraph style in find/replace), but in a way that no longer works.

    Second question is: given to split the find/replace in two steps, how then transform / apply to newly created paragraph the correct style of Bus?

    Thank you in advance for your valuable assistance. So far, the community has been great!

    Antonio

    Original

    Screen Shot 2016-07-12 at 22.32.23.png

    Result for

    Screen Shot 2016-07-12 at 22.54.51.png

    Hi Antonio,.

    If I understand correctly, in 2 regex [1 click play with Multi/find-replace our friend Martinho da Gloria]:

  • Find/replace preference - include locked, locked layer the objects (Find only)

    Hi all

    I was wondering if anyone can help, I'm trying to make sure that the option "Include Locked layers and objects locked (research only)" on the box search/replace is active when the script below is executed because when it is disabled the text find/replace does not check locked layers and objects.

    In InDesign this icon located in the Find/Replace dialog box, a little less the "search:" drop down menu, icon of the left hand.

    Replace the text "Page Type"

    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

    app.findTextPreferences.findWhat = "Page Type";

    {found = app.activeDocument.findText () [i] = "STET".silence ;}

    Any help would be great thanks, Brendan

    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

    app.findChangeTextOptions.includeLockedLayersForFind = true;

    app.findTextPreferences.findWhat = "Page Type";

    {found = app.activeDocument.findText () [i] = "STET".silence ;}

  • Find/replace style cell with GREP

    Hi all, (my first post here)

    I found a script very useful on this forum to find/replace cell styles in an array. I adapted the script using Peter Kahrel ebook for use with a GREP query.

    I've linked to a spreadsheet in InDesign CC 2014 I want to highlight the cell of new products that contain the value [Y].

    When I run the script below, I get random results.

    myDoc = app.activeDocument var

    app.findGrepPreferences = app.changeGrepPreferences = null

    app.findGrepPreferences.findWhat = "\[\u\"]

    var myFound = myDoc.findGrep)

    for (i = 0; i < myFound.length; i ++)

    {

    If (. parent.constructor.name myFound [i] == "Cell")

    {

    . parent.appliedCellStyle myFound [i] = "New_Product_Cell".

    }

    }

    Modify the script that I wrote above.

    Otherwise your discovery is just '[u]' ==> multi-ad found is--> Direct manufacturer name


    Jarek

Maybe you are looking for