GREP find/change problem

Hi, am trying to execute InDesign's default find/change AppleScript script to fix many formatting issues in a large document. One of them is occurences of a two-digit dollar figure followed by a comma (eg. "$10,") that needs to be changed to have no comma.
Using GREP I can pick it up by finding "\$\d\d," but when I replace it with "\$\d\d" I get the actual string "\$\d\d". IE. "$10," becomes "\$\d\d" rather than "$10". Am I misundersting how the 'change' part of GREP works? Can any one advise?
FYI the line in the find/change support .txt doc is:
grep
{find what:"\\$\\d\\d,"}
{change to:"\\$\\d\\d"}
{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}
Remove commas after prices.
...which includes extra backslashes to escape the backslashes that are part of the GREP expression.
Any help much appreciated!
Thanks.

No, unfortunately lookbehinds don't work with variable-length strings. That's the case with all GREP implemantations, not just InDesign's. You can sort of get around it by using or-constructs, but they soon become unmanageable. Here's an example (split and indented just for clarity, you would need to write all this on one line):
     (?<=\$\d)
     |
     (?<=\$\d\d)
     |
     (?<=\$\d\d\d)
This one says "if a comma is preceded by $ and a digit OR by $ and two digits OR by $ and three digits, then . . ." As you understand, if you need to allow up to six or seven digits, possibly thousand separators too, then lookbehinds become unpracticable.
>I'm really struggling to get to grips with how GREP statements work.
Try this: http://oreilly.com/catalog/9780596156008/
Peter

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.

  • 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

  • Text or GREP find/change method to assign tags

    Hi all
    I could use a text or GREP find/change method to  assign tags to paragraph styles (for use in FindChangeByList), would anyone be able to help please?
    Steve

    Hi Peter
    I produce a quarterly magazine for which text is supplied in Word format.
    I currently run the 'FindChangeByList' script to format body text, headings, bulleted and numbered lists, web and email address text styling and to remove/correct all extraneous characters etc.
    Once the job is printed I need to produce a tagged 'accessible' readable (eg: read out loud function in Acrobat) pdf from the file, for text to speech readers.
    I am currently using the map tags to styles function, which allows me to assign tags which in turn gives me control of the 'text reading' order.
    What I'd like to be able to do is automatically apply the Tags to syles while processing the 'FindChangeByList' script.
    Steve

  • Applescript find/change problem

    I have some text which needs to be styled in InDesign CS4 which has a bunch of extraneous tags ( eg. <b>, <i>, etc.). I have customised the FindChangeList.txt file that supports the FindChangeByList.applescript file to do things like:
    {find what:"<i>"}
    {change to:"^S"}
    which can then be picked up by a nested style. All good so far.
    Problem: the applescript will just not 'see' the strings <b> or </b> in FindChangeList.txt. It treats them like they aren't there. I can do it using the find/replace within InDesign, it works fine there, but my problem is that I have hundreds of pieces of copy to import and I'd like to automate as much as possible. Using GREP has the same effect, ie. works in find/replace within InDesign, but not with applescript.
    Any help would be greatly appreciated as this is really killing me at the moment. Thanks!
    Content of FindChangeList.txt follows. The command in the final line works, the command in the second-last line doesn't.
    (FYI the second line of code contains 'InDesign CS3' regardless of whether I use CS3 or CS4. I guess they didn't update the file)
    --FindChangeList.txt
    --A support file for the InDesign CS3 AppleScript FindChangeByList.applescript
    --This data file is tab-delimited, with carriage returns separating records.
    --The format of each record in the file is:
    --findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    --Where:
    --<tab> is a tab character
    --findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    --findProperties is a properties record (as text) of the find preferences.
    --changeProperties is a properties record (as text) of the change preferences.
    --findChangeOptions is a properties record (as text) of the find/change options.
    --description is a description of the find/change operation
    --Very simple example:
    --text          {find what:"--"}          {change to:"^_"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find all double dashes and replace with an em dash.
    --More complex example:
    --text          {find what:"^9^9.^9^9"}          {applied character style:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".
    --All InDesign search metacharacters are allowed in the "find what" and "change to" properties.
    text          {find what:"<b>"}          {change to:"^S"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find all bold and replace with non-breaking space.
    text {find what:"<i>"} {change to:"^S"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all italics and replace with non-breaking space.

    You probably should post this in the ID Scripting forum. Here's an example of some simple AppleScript find and changes that might help:
    --find and replace keyboard formating
    tell application "Adobe InDesign CS5.5"
         --first clear the preferences
         set find text preferences to nothing
        set change text preferences to nothing
        --replaces non breaking space with space
        set find what of find text preferences to "^s"
        set change to of change text preferences to "<0020>"
        set myFoundItems to change text
        --replaces soft return with return
        set find what of find text preferences to "^n"
        set change to of change text preferences to "^p"
        set myFoundItems to change text
        --replaces return space with return
        set find what of find text preferences to "^p<0020>"
        set change to of change text preferences to "^p"
        set myFoundItems to change text
        --replaces 2 returns with return
        set find what of find text preferences to "^p^p"
        set change to of change text preferences to "^p"
        set myFoundItems to change text
        --replaces return, tab, return with return
        set find what of find text preferences to "^p^t^p"
        set change to of change text preferences to "^p"
        set myFoundItems to change text
        --replaces space, return with return
        set find what of find text preferences to "<0020>^p"
        set change to of change text preferences to "^p"
        set myFoundItems to change text
        --replaces space, space with space
        set find what of find text preferences to "<0020><0020>"
        set change to of change text preferences to "<0020>"
        set myFoundItems to change text
        --replaces 3 tabs with tab
        set find what of find text preferences to "^t^t^t"
        set change to of change text preferences to "^t"
        set myFoundItems to change text
        --replaces 2 tabs with tab
        set find what of find text preferences to "^t^t"
        set change to of change text preferences to "^t"
        set myFoundItems to change text
    end tell

  • Find/Change problems within a nested style?

    I have a problem with Find/Change (in both CS4 and CS5) not recognizing text within its “find” parameters when text that fits those parameters is part of a nested style. I want to find any instance of italic in the text, regardless of what paragraph or character style it is, but F/C only intermittently finds italics, both within and without that text existing in a nested style. Has anyone come across this issue?
    There is NOTHING different about the text that is recognized by F/C–or not recognized–that shows up in any of the panels or palettes. There are no font conflicts. I’ve replaced prefs and saved data files. If I go into the character palette and change the italic portion of the nested style to “italic” character style (it shows up in character palette as [none], even though it has a nested style), then F/C finds it for sure; but if I don’t do that, then F/C will sometimes find it, and sometimes not, and sometimes in one instance and not in another! There is no hidden formatting that shows up in story editor. I remade another nested para style with the same formatting but with varying results! Help… I’ve tried everything.

    I have a problem with Find/Change (in both CS4 and CS5) not recognizing text within its “find” parameters when text that fits those parameters is part of a nested style. I want to find any instance of italic in the text, regardless of what paragraph or character style it is, but F/C only intermittently finds italics, both within and without that text existing in a nested style. Has anyone come across this issue?
    There is NOTHING different about the text that is recognized by F/C–or not recognized–that shows up in any of the panels or palettes. There are no font conflicts. I’ve replaced prefs and saved data files. If I go into the character palette and change the italic portion of the nested style to “italic” character style (it shows up in character palette as [none], even though it has a nested style), then F/C finds it for sure; but if I don’t do that, then F/C will sometimes find it, and sometimes not, and sometimes in one instance and not in another! There is no hidden formatting that shows up in story editor. I remade another nested para style with the same formatting but with varying results! Help… I’ve tried everything.

  • Find/Change problem

    Hi, I'm trying to do a find/change that finds the first space after text that is tagged with a specific character style, called name, and change it to an en space. So, for example, if I had text:
    Cowboy buckeroo or vaquero
    Cowboy has the name char. sty. applied and I would like to change the space between Cowboy and buckeroo to an en space, but leave the the spaces on either side of or to remain as they are.
    I can't figure out how to do it...can anyone help?
    thanks

    Eugene,
    I only had to do this part:
    Do a GREP search for
    Find
    (.+)
    Change to
    $1~>
    Find Format:
    <charstyle>
    Not sure what the last search does?
    Thanks very much
    Jon

  • InDesign Scripting or GREP Find/Change?

    Can anyone help me with a script or GREP idea for finding, cutting and pasting the phone numbers at the end of these paragraphs? The first one is what I have and the second is where I would like to get. There are hundreds of these in 4 restaurant directories that I am designing.
    Woodlands (ve) Indian. Weekend buffet. 4078 Jermantown Road. (703) 385-1996. M–F 11:30am–10pm, Sa 11:30am–10pm, Su 11:30 am–9:30pm.
    Woodlands (ve) Indian. Weekend buffet. 4078 Jermantown Road. M–F 11:30am–10pm, Sa 11:30am–10pm, Su 11:30 am–9:30pm. (703) 385-1996.

    You don't need to ask the same question twice. Lets keep all the discussion inthe original topic please,
    http://forums.adobe.com/message/3856456#3856456
    If you are not able to make the anser I provide there work, please provide some details about what is not working, and some before and after screen shots.

  • GREP query for find/change operation

    Hi everyone,
    In the following line, there's a comma after the first name. This type of formatting is repeated hundreds of times on a number of pages so I need to use a GREP find/change query to remove the comma after the first name and replace it with a space.
    Firstname,Lastname,State
    I wondered if something could tell me what the GREP code would be?
    Appreciate any assistance.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    ..  it's also doing it for the second comma
    That's impossible. You must have entered something else than Scott's code.

  • Find/Change words (with GREP) and apply a style...

    I need a Script for Find/Change words with GREP, and apply a paragraph style...
    Thanks...

    Hi Marcos,
    If you want the script to create character styles: Bold , Italic, Bold Italic, etc, and replace local formatting with these styles, use scripts in post #3.
    But if you want find and change words, or/and replace local formatting with styles defined by you, use FindChangeByList script.
    If the latter, I recommend you to download and install Record Find Change script (written by Martin Fisher).
    Then choose settings you need in Find-Change dialog – make sure they work as expected – and run Record Find Change script. A Notepad/TextEdit file will pop up with a line containing the recorded setting. Copy it, open FindChangeList.txt, delete the contents of this file and paste the line you just copied (or add it to the bottom of the file).
    Repeat the process for all find-change operations you need.
    Finally run FindChangeByList.jsx to make all changes in one go.
    However, while using Record Find Change script, you may encounter a problem: it doesn’t record paragraph and character styles placed inside a group. But you can write references to such styles like so:
    appliedParagraphStyle:app.activeDocument.paragraphStyleGroups.item("Style Group 1"). paragraphStyles.item("Paragraph Style 1")
    Kasyan

  • Find/Change GREP - FindChangeByList - help!

    Hi,
    Can anyone help with my GREP problem? I have a long unformatted list of products, I need a couple of GREP find and change queries to help format the list. The formatting will be based on paragraph styles for product header, description and product code. I have GREP working correctly to find the product code lines and apply the 'product code' paragraph style, but I'm struggling to target the product header line. The product header is on the next line after the product code, or it could be found on the line above the product description. I need GREP to find the product header to apply the product header paragraph style. I'm looking at using FindChangeByList; so far I have the folowing:
    grep
    {findWhat:"(Product Code|Product code)$"}
    {appliedParagraphStyle:"Product Code-green"}
    The above line finds all the Product Codes and applies the paragraph style. It works perfectly well from Indesigns Find/Change panel and FindChangeByList.
    But the next bit doesn't work:
    grep
    {findWhat:"^(?<=\\r)", appliedParagraphStyle:"Product Code-green"}
    {changeTo:"", appliedParagraphStyle:"Product Header-green"}
    I've tried to target the 'Start of a paragraph (^)' (this will be the product header) that has - 'Paragraph Break (\r)' with the 'Product Code-green' applied (this is the product code), in front of it. - (Am I right in thinking that in the FindChangeByList script I need 2 slashed on \\r - I have tried with 1 and 2 - no joy.)
    If I do this in Indesigns Find/Change panel it does kind of work. If I click find, it will find the correct point, and click change, it will apply the correct style to the product header - BUT if I click CHANGE ALL - it doesn't work. It reports '0' instances found, yet if i click Find again it will find the next instance. So it's kind of working on an individual click and find basis, but not on global change all - STRANGE? And it doesn't work at all when run from FindChangeByList.
    Anybody got any thoughts on why this is happening? or a better piece of GREP to try? Would really like it to be running from FindChangeByList. Hope the above makes sense.
    Thanks

    Hi,
    You can go straight or try to modify 'MultiFind' script.
    I suggest to use a text conditions and go straight with this code:
    var
              mDoc = app.activeDocument,
              mCond = mDoc.conditions.item("mFound"),
              mPath = "~/Documents/ID_words_to_find.txt",
              mDelimiter = ",",
              mSource = File(mPath),
              mOpen = mSource.open("r",undefined,undefined),
              len, len1, mWordsArr, mFound;
    if (!mCond.isValid)
              mCond = mDoc.conditions.add({
                        name: "mFound",
                        indicatorColor: UIColors.LIGHT_BLUE,
                        indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT,
                        underlineIndicatorAppearance: ConditionUnderlineIndicatorAppearance.SOLID
    if ( !mOpen) {alert ("Can't open a source file"; exit()};
    mWordsArr = mSource.read().split(mDelimiter);
    len = mWordsArr.length;
    app.findTextPreferences = null;
    while (len-->0) {
              app.findTextPreferences.findWhat = mWordsArr[len];
              mFound = mDoc.findText();
              len1 = mFound.length;
              while (len1-->0)
                        mFound[len1].appliedConditions = [mCond];
    app.findTextPreferences = null;
    How it works (should)?
    Assumed:
    - a list of words to find is in a .txt file as comma-delimited (you could set other delimiter)
    - this file is named 'ID_words_to_find'  and saved in user Documents folder (you can change mPath)
    Script define a condition 'mFound' and apply it to every word from your list found in a document. They are highlighted. You can modify them.
    Notice: to remove a condition (highlight) modify a word including a space before it.
    Enjoy:)
    Jarek

  • Text find and change problem in CS3 and CS4 script

    I use the script below to find some text and change into others.
    There is one thing the script can't do it for me.
    Example:
    (g) Management
    (1) that no law which is enacted in the Cayman Islands imposing any tax to be levied on profits, income, gains or appreciation shall apply to the Company or its operations; and
    (2) that the aforesaid tax or any tax in the nature of estate duty or inheritance tax shall not be payable on or in respect of the shares, debentures or other obligations of the Company.
    Example:(END)
    I got a lot of topics or points in the passage. And I want to change the space between '(g)' and 'Management' into a tab character. So I revised the plain text file 1text.
    PS: 1text.txt is filled with what to change.
    text {findWhat:"^p(^?) "} {changeTo:"^p(^?)^t"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all space-dash-space and replace with an en dash.
    The result is:
    (^?)^tManagement
    (^?)^tthat no law which is enacted in the Cayman Islands imposing any tax to be levied on profits, income, gains or appreciation shall apply to the Company or its operations; and
    (^?)^tthat the aforesaid tax or any tax in the nature of estate duty or inheritance tax shall not be payable on or in respect of the shares, debentures or other obligations of the Company.
    PS: ^t is a tab character.
    result (END)
    This is not what I want.
    It should be '(g)^tManagement'.
    PS: ^t is a tab character.
    Please someboady help me out to revised the script below to change the text into what I want. Thanks so much.
    Here is the script.
    //FindChangeByList.jsx
    //An InDesign CS4 JavaScript
    @@@BUILDINFO@@@ "FindChangeByList.jsx" 2.0.0.0 10-January-2008
    //Loads a series of tab-delimited strings from a text file, then performs a series
    //of find/change operations based on the strings read from the file.
    //The data file is tab-delimited, with carriage returns separating records.
    //The format of each record in the file is:
    //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    //Where:
    //<tab> is a tab character
    //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    //findProperties is a properties record (as text) of the find preferences.
    //changeProperties is a properties record (as text) of the change preferences.
    //findChangeOptions is a properties record (as text) of the find/change options.
    //description is a description of the find/change operation
    //Very simple example:
    //text {findWhat:"--"} {changeTo:"^_"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double dashes and replace with an em dash.
    //More complex example:
    //text {findWhat:"^9^9.^9^9"} {appliedCharacterStyle:"price"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find $10.00 to $99.99 and apply the character style "price".
    //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
    //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
    //as shown in the example below:
    //{findWhat:"\\s+"}
    //For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
    //or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
    main();
    function main(){
    var myObject;
    //Make certain that user interaction (display of dialogs, etc.) is turned on.
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    if(app.documents.length > 0){
      if(app.selection.length > 0){
       switch(app.selection[0].constructor.name){
        case "InsertionPoint":
        case "Character":
        case "Word":
        case "TextStyleRange":
        case "Line":
        case "Paragraph":
        case "TextColumn":
        case "Text":
        case "Cell":
        case "Column":
        case "Row":
        case "Table":
         myDisplayDialog();
         break;
        default:
         //Something was selected, but it wasn't a text object, so search the document.
         myFindChangeByList(app.documents.item(0));
      else{
       //Nothing was selected, so simply search the document.
       myFindChangeByList(app.documents.item(0));
    else{
      alert("No documents are open. Please open a document and try again.");
    function myDisplayDialog(){
    var myObject;
    var myDialog = app.dialogs.add({name:"FindChangeByList"});
    with(myDialog.dialogColumns.add()){
      with(dialogRows.add()){
       with(dialogColumns.add()){
        staticTexts.add({staticLabel:"Search Range:"});
       var myRangeButtons = radiobuttonGroups.add();
       with(myRangeButtons){
        radiobuttonControls.add({staticLabel:"Document", checkedState:true});
        radiobuttonControls.add({staticLabel:"Selected Story"});
        if(app.selection[0].contents != ""){
         radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
    var myResult = myDialog.show();
    if(myResult == true){
      switch(myRangeButtons.selectedButton){
       case 0:
        myObject = app.documents.item(0);
        break;
       case 1:
        myObject = app.selection[0].parentStory;
        break;
       case 2:
        myObject = app.selection[0];
        break;
      myDialog.destroy();
      myFindChangeByList(myObject);
    else{
      myDialog.destroy();
    function myFindChangeByList(myObject){
    var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
    var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
    var myStartCharacter, myEndCharacter;
    var myFindChangeFile = myFindFile("/FindChangeSupport/1test.txt")
    if(myFindChangeFile != null){
      myFindChangeFile = File(myFindChangeFile);
      var myResult = myFindChangeFile.open("r", undefined, undefined);
      if(myResult == true){
       //Loop through the find/change operations.
       do{
        myLine = myFindChangeFile.readln();
        //Ignore comment lines and blank lines.
        if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0, 5)=="glyph")){
         myFindChangeArray = myLine.split("\t");
         //The first field in the line is the findType string.
         myFindType = myFindChangeArray[0];
         //The second field in the line is the FindPreferences string.
         myFindPreferences = myFindChangeArray[1];
         //The second field in the line is the ChangePreferences string.
         myChangePreferences = myFindChangeArray[2];
         //The fourth field is the range--used only by text find/change.
         myFindChangeOptions = myFindChangeArray[3];
         switch(myFindType){
          case "text":
           myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
           break;
          case "grep":
           myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
           break;
          case "glyph":
           myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
           break;
       } while(myFindChangeFile.eof == false);
       myFindChangeFile.close();
    function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
    //Reset the find/change preferences before each search.
    app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences = NothingEnum.nothing;
    var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
    myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
    myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
    app.doScript(myString, ScriptLanguage.javascript);
    myFoundItems = myObject.changeText();
    //Reset the find/change preferences after each search.
    app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences = NothingEnum.nothing;
    function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
    //Reset the find/change grep preferences before each search.
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences = NothingEnum.nothing;
    var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
    myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
    myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
    app.doScript(myString, ScriptLanguage.javascript);
    var myFoundItems = myObject.changeGrep();
    //Reset the find/change grep preferences after each search.
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences = NothingEnum.nothing;
    function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
    //Reset the find/change glyph preferences before each search.
    app.changeGlyphPreferences = NothingEnum.nothing;
    app.findGlyphPreferences = NothingEnum.nothing;
    var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
    myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
    myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
    app.doScript(myString, ScriptLanguage.javascript);
    var myFoundItems = myObject.changeGlyph();
    //Reset the find/change glyph preferences after each search.
    app.changeGlyphPreferences = NothingEnum.nothing;
    app.findGlyphPreferences = NothingEnum.nothing;
    function myFindFile(myFilePath){
    var myScriptFile = myGetScriptPath();
    var myScriptFile = File(myScriptFile);
    var myScriptFolder = myScriptFile.path;
    myFilePath = myScriptFolder + myFilePath;
    if(File(myFilePath).exists == false){
      //Display a dialog.
      myFilePath = File.openDialog("Choose the file containing your find/change list");
    return myFilePath;
    function myGetScriptPath(){
    try{
      myFile = app.activeScript;
    catch(myError){
      myFile = myError.fileName;
    return myFile;

    It takes me a lof of time to comprehend the sentence you write. Cause I am a Chinese. My poor English.
    I have to say "you are genius". I used to use the indesign CS2. There is no GREP function in CS2. When I get the new script, I do not know how to use it. Just when I saw the
    'grep {findWhat:"  +"} {changeTo:" "} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false} Find all double spaces and replace with single spaces.'
    Being confused.
    Thanks so much. It seems I have to relearn the advanced Indesign.

  • Find/Change Grep only finds one instance per paragraph, where am I going wrong?

    Hi,
    I've been using a Find/Change Grep to find any price with a comma and change that comma to a thin space (Newspaper's editorial style).
    But the Grep only finds the first instance of this per paragraph.
    Sample text...
    "$200,000 $200,000 $200,000.
    text at start of paragraph $200,000
    $200,000 text at end of paragraph
    tab     $200,000."
    In the sample the grep would miss the second and third price on the first line.
    I've been using...
    Find...
    (?<=\$)(\d{3})\,?(\d{3})
    also tried (\$\d{3})\,?(\d{3})
    Change to...
    $1~<$2
    Is there anything I can add to find these last two prices?
    I've been using this in combination with Batch Find Replace script, so different greps are set up for 5,6 and 7 digit numbers that start with $.
    Thanks.

    Try this,
    Find what: (?<=\x{0024})(\d{3})\,?(\d{3})
    Change to: $1~<$2
    Vandy

  • [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.

  • Path of the Find-Change Queries/Grep folder in ID CC 2014

    Hi,
    Is this var correct to localize the path of the Find-Change Queries/Grep folder in ID CC 2014?
    var query_folder = app.scriptPreferences.scriptsFolder.parent.parent + "/Find-Change Queries/Grep/";
    Thanks in advance! 

    Hello,
    Alert ( app.scriptPreferences.scriptsFolder.parent.parent );
    Mac ID 6, give me this.
    I will have a look at CC later.
    P

Maybe you are looking for

  • Changing filename causes all finder windows to close

    changing a filename causes all open finder windows to close and desktop icons to briefly disappear. This problem just started. Anybody have this problem? Thanks, Tim.

  • Siebel Marketing ESD not sending Email

    I have installed Siebel Marketing and configured it to send email through launching campaigns. Without intervention of ESD, my emails through F9 (Menu bar->File->Send Email) goes fine but when i send it through a campaign it is not received at the ot

  • App Designer/Compare Reports

    Anyone? Could someone please give some guidance on how they typically run Compare Reports either in App Designer or through Change Assistant? We were recently upgraded from 8.9 to 9.2 and I've newly assumed the role of administering our PeopleSoft sy

  • Dreamweaver CS4 serial number invalidated after 8 months of use

    In January 2nd 2014, I purchased an OEM version of Dreamweaver CS4 for Windows from a reseller called "Smart Shop" which looked like a serious outfit [emails from Jet Support were received with a link to "Access your order and customer support http:/

  • Bridge icons missing

    After update 2.0 continue same bug, ramdomly the bridge icons dissapear, what is the problem with that....