Help with search and replace script please

Hi all
I've written a javascript which uses various GREP and text find/changes to copy some text from the first two paragraphs of a document and use them elsewhere (in the running head and footers) and now I want to delete the first two paragraphs. Not sure how I would do that. If I was doing a manual find/change (with nothing selected) it would automatically select the first para in the first text box but when I run teh following;
app.findGrepPreferences.findWhat = "^.+$";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
it finds all paragraphs and deletes them. I was going to include the code twice; once to delete the first paragraph and then again to delete the other (new first) paragraph. My JS skills are shaky but I'm quite comfortable with GREP. Can anyone point me in the right direction for how I acheive what I want? If I did a for loop surely I'd just be doing the same thing but more than once!
Much to my surprise the rest of the script is working although it made my brain hurt!
thanks for any suggestions,
Iain

Oooh. After
myStory=app.activeDocument.stories.everyItem();
the variable "myStory" won't point to just a single story, but ... to "every story". So that's why the next line removes more than you intended!
What the "everyItem" thingy internally does is still unclear to me, but that doesn't keep me from using it -- but only when you absolutely, positively want to perform an action on every item
Now the usual examples say something like
myStory = app.activeDocument.stories.item(0); // access first story
but that's No Good. Even if your first story is the one you are targeting today, tomorrow, in a different document, it'll be story #1, or #5, or #255. There is no general rule that states the first story is always the largest one, or something like that.
If this is going to be used with a document template, the best way to identify the target story is by giving the first text frame a unique label. Otherwise, you'll have to think of something else ... A couple of other strategies:
1. You are already using GREP to find stuff. If one of those searches is guaranteed to return just text in the one story you are interested in, you can use this.
2. You mention headers and footers. If your main text is the only one that runs through multiple text frames, you can loop over all stories and check which one runs through than a single text frame.
3. ... (I'm pretty sure there are some more strategies ...)

Similar Messages

  • Help with searching and replacing

    This kind of carries on from the previous topic i posted, but that one came to a bit of a dead end. Here is the code that i have so far:
    import java.io.*;
    import java.util.*;
    class SearchReplaceApp
         public static InputStreamReader input =
         new InputStreamReader(System.in);
         public static BufferedReader keyboardInput =
         new BufferedReader(input);
         public static void main(String[] args) throws IOException
         FileReader file = new FileReader(args[0]);
         BufferedReader MyFile = new BufferedReader(file);
              StringTokenizer TokenizeMe;
              int NumberOfTokens = 0;
              int NumberOfWords = 0;
         TokenizeMe = new StringTokenizer(MyFile.readLine());
         NumberOfTokens = TokenizeMe.countTokens();
         while (NumberOfTokens != 0)
              for (int WordsInLine=1; WordsInLine<=NumberOfTokens;
                        WordsInLine++)
                   System.out.print(TokenizeMe.nextToken()+" ");
              System.out.println();
              NumberOfWords += NumberOfTokens;
              String line = MyFile.readLine();
              if (line==null) break;
              TokenizeMe = new StringTokenizer(line);
              NumberOfTokens = TokenizeMe.countTokens();
              String findWord;
              String replaceWord;
              System.out.println ("Search for?:");
              findWord = keyboardInput.readLine();
              System.out.println("Replace With?:");
              replaceWord = keyboardInput.readLine();
              if (line.equals(findWord)) {               
              line = replaceWord;
         System.out.println("\nThis file contains " + NumberOfWords + " words");
         MyFile.close();
         }The problem is that it asks to search for a word after it has read each line of the file to the screen, instead of just asking when it has read in the whole file, which is what i want it to do. can anyone help me with this?
    I think the problem lies in the part :
              String findWord;
              String replaceWord;
              System.out.println ("Search for?:");
              findWord = keyboardInput.readLine();
              System.out.println("Replace With?:");
              replaceWord = keyboardInput.readLine();
              if (line.equals(findWord)) {               
              line = replaceWord;
    I would also like the program to display the dedited text after the replace has been completed e.g.
    java SearchReplaceApp test.txt
    This is a test
    This is a test
    This is a Test
    This is a Test
    This file contains 16 words
    Search for?: test
    Replace with?: Test
    This is a Test
    This is a Test
    This is a Test
    This is a Test
    Search for?:
    etc............................
    Any help at all would be appreaciated as im getting a bit frustated with this program and also my own lack of knowledge.
    Thanks
    Max

    Hi,
    sorri for that code which sent. here's is the correct code
    import java.io.*;
    import java.util.*;
    class SearchReplaceApp
    public static InputStreamReader input = new InputStreamReader(System.in);
    public static BufferedReader keyboardInput = new BufferedReader(input);
    public static void main(String[] args) throws IOException
    FileReader file = new FileReader(args[0]);
    BufferedReader MyFile = new BufferedReader(file);
    StringTokenizer TokenizeMe;
    int NumberOfTokens = 0;
    int NumberOfWords = 0;
    String line = MyFile.readLine();
    String completeText = "";
    Vector strVec = new Vector();
    while(line!=null)
    completeText+="\r\n";
    StringTokenizer tokenizeLine = new StringTokenizer(line);
    NumberOfWords+=tokenizeLine.countTokens();
    completeText +=line;strVec.add(line);
    line = MyFile.readLine();
    MyFile.close();
    System.out.println(completeText);
    System.out.println("This file contains"+NumberOfWords+ "words");
    String findWord="";
    String replaceWord;
    String resultStr = "\r\n";
    for ( ;;)
    System.out.println ("Search for?:");
    System.out.println("Please enter quit for quit:");
    findWord = keyboardInput.readLine();
    if(findWord.equals("quit")) break;
    //While findWord is not =null do.......
    System.out.println("Replace With?:");
    replaceWord = keyboardInput.readLine();
    for(int i=0;i<strVec.size();i++)
    String str = (String)strVec.get(i);
    TokenizeMe = new StringTokenizer(str);
    while ( TokenizeMe.hasMoreTokens())
    String token = TokenizeMe.nextToken();
    if (token.trim().equals(findWord.trim()))
    token = replaceWord; resultStr+=" " +token;
    else{resultStr+=" "+token;}}resultStr+="\r\n";
    System.out.println("COMPLETE TEXT AFTER REPLACE IS "+resultStr);
    //Save changes back to original file
    String str = resultStr;
    FileWriter newFile = new FileWriter(args[0]);
    PrintWriter fw = new PrintWriter(newFile);
    char[] ch = new char[str.length()];
    str.getChars(0,str.length(),ch,0);
    fw.write(ch);
    fw.flush();
    fw.close();
    hope this solves your problem.
    shyam

  • Problem with search and replace

    I'm workin on Windows XP, Dreamwearver 8
    When I do a search and replace in a site, the changes will be
    made correctly, however, the auto date stamp that I'm using on my
    pages will duplicate on random pages and overwrite text This
    doesn't occur on all pages, and isn't connected with the actual
    change I'm making. Has anyone experienced this?

    Ok Gary, but...
    in a SQLWorksheet write:
    ababab
    Now Edit -> Replace search for b , replace with \nb
    Result (the last b is not replaced):
    a
    ba
    bab
    At this point, I want to have my string back on one line: Edit -> Replace search for \n , replace with (nothing here)
    Result: The search text "\n" was not found.
    And to make it work I have to tick the Regular Expressions checkbox (in this case substitute escaped characters is ignored).
    While I agree that "it is good to have a choice", I personally find it confusing: none of the few text editors I use (Linux or OSX) behaves this way.
    Regards.
    Alessandro

  • Need Help With find and Replace

    I am a little green to this all. I am trying to find and
    replace a word inside the edit region and Dreamweaver will not
    change it, because it says its inside a locked region, but its a
    editable region?
    I have about 900 pages I need to make this change on and was
    relying on the find and replace tool to do that. I tried differn't
    advanced options, nothing seams to change it. I am using cs3.
    Thanks for any help

    Using Templates with a 900 page site is a crime against
    humanity. You reach
    the optimal size for Templates between about 50 and 100.
    The error you are getting suggests that there are coding
    errors on the page
    (perhaps even unrelated to ANY DW Template markup). We'd need
    to see the
    page to make progress with what that might be, as Alan says.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "RyanWaters" <[email protected]> wrote in
    message
    news:ggs7fq$gnq$[email protected]..
    >I am a little green to this all. I am trying to find and
    replace a word
    >inside
    > the edit region and Dreamweaver will not change it,
    because it says its
    > inside
    > a locked region, but its a editable region?
    > I have about 900 pages I need to make this change on and
    was relying on
    > the
    > find and replace tool to do that. I tried differn't
    advanced options,
    > nothing
    > seams to change it. I am using cs3. Thanks for any help
    >

  • Help with find and replace regex

    Hello.
    I have a page listing about 50 services that have named
    anchors to a
    glossary page. Something like this:
    <a href="/glossary.html#Blogging">Blogging</a>
    And what I need is to have the glossary open in a new window.
    So how
    do I write a regex that will give me:
    <a href="/glossary.html#Blogging"
    taget="blank">Blogging</a>
    Thanks for any help
    Lance

    Thanks Brendon.
    It's Regular Expression; an optioin in the find and replace
    dialog.
    I've got to replace 50 of these anchors, each different.
    <a href="/glossary.html#Blogging">Blogging</a>
    <a href="/glossary.html#yadayada">yadayada</a>
    etc.
    to make them each open in a new window.
    <a href="/glossary.html#Blogging"
    taget="blank">Blogging</a>
    L.
    On Thu, 18 Oct 2007 14:40:46 +1300, "Brendon"
    <[email protected]>
    wrote:
    >Whats a regex?
    >Why not just do a Find and Replace? Specify the current
    local site, and
    >voila. Make sure you spell target correctly though ;-)
    >
    >
    ><@networkologist@@gmail.com> wrote in message
    >news:[email protected]..
    >> Hello.
    >>
    >> I have a page listing about 50 services that have
    named anchors to a
    >> glossary page. Something like this:
    >>
    >> <a
    href="/glossary.html#Blogging">Blogging</a>
    >>
    >> And what I need is to have the glossary open in a
    new window. So how
    >> do I write a regex that will give me:
    >>
    >> <a href="/glossary.html#Blogging"
    taget="blank">Blogging</a>
    >>
    >> Thanks for any help
    >>
    >>
    >>
    >> Lance
    >

  • Help with automator and folder actions please

    Hi all!
    I'd like to attach a folder action to a folder, so that any time i drag something in it, it'll be sent to my mobile phone.
    I just dont get it how to do it.
    Can please someone help? I'm totaly incapable of writing an applescript to do so...
    Best regards,

    Hi!
    So next step...
    I create a folder so and right-click "configure actions" (sorry my
    system is french so the terms are probably different on the US
    system....)
    Automator launches, and I add the push to BT part to my workflow. I save
    it all, and return to the finder.
    I right click on the folder, the script appears as it should.
    I click on the created script, a window opens with the device selection.
    I click OK. and get a message saying that this kind of file (a standard
    .sis file) won't be accpted from my device (a 6680 nokia). I click "try
    anyway", the window of file transfer opens, but I get the error
    "Transfer failed, operation not handled".
    I don't get it. Where did I go wrong?
    Thanx fo your feedback!

  • Need help with date and time calculations please

    Hello there.. Im stuck, and im hoping someone can help..
    Working on a list to manage and track PTO.  User completes PTO request form,
    Fields
    Name
    Start Date (with time)
    End Date (with time)
    Total Number of Days/hours requested: (calculation)
    Full Day: (Yes/No)
    ok business need
    user has the ability to request a certain number of hours as opposed to a full day.
    After searching around on google. I found this calculation to help me figure out how many BUSINESS days being requested.
    =IF(ISERROR(DATEDIF([Start Date],[End Date],"d")),"",(DATEDIF([Start Date],[End Date],"d"))+1-INT(DATEDIF([Start Date],[End Date],"d")/7)*2-IF((WEEKDAY([End Date])-WEEKDAY([Start Date]))<0,2,0)-IF(OR(AND(WEEKDAY([End
    Date])=7,WEEKDAY([Start Date])=7),AND(WEEKDAY([End Date])=1,WEEKDAY([Start Date])=1)),1,0)-IF(AND(WEEKDAY([Start Date])=1,(WEEKDAY([End Date])-WEEKDAY([Start Date]))>0),1,0)-IF(AND(NOT(WEEKDAY([Start Date])=7),WEEKDAY([End Date])=7),1,0))
    This works great as long as its a [Full Day]="YES", displays results in column labeled Number of days
    now if [Full Day]="No", displays results in column labeled Number of Hours
    BUT this is my issue (well part of it) it calcuate the correct number of hours.. but puts a "1" in "Number of Days" why.. dates have not changed.. I think Its something with the above calculation but I could be way off.
    the end result is I need number of days to concat with number of hours 
    i.e 1 full day 4 hours  1.4
        0 full day 5 hours  0.5
        1 full day 0 hours  1.0
    so that the total can be deducted via workflow.. from the remaining balance in a tracker. (seperate list) 
    Any angels out there??

    Posnera-
    Try changing time zones and see if the travel itinerary times change.
    Fred

  • Help with sqlplus and running script

    Hi,
    I have some software that uses Oracle for it's database. However the supporting documentation is pretty thin and expects the product to be installed by a professional.
    I've installed the prodyct and created a database mfdb.
    My documentation says, run:
    $ORACLE_HOME/bin/sqlplus username@service name
    Then, to run the script in sqlplus use
    @schema_oracle.sql
    Please can someone advise me what the username@service name should be, or how I determine these? I'm not concerned with security, just need to test the software.
    Thanks in advance.
    Mark

    Mark,
    If you are connecting to the database from the local machine you should be able to leave out the service name part as SQL*Plus will connect to the default database. You should have been asked during the install to enter passwords for some standard users. Which version of Oracle are you using?
    Try some of these:
    $ORACLE_HOME/bin/sqlplus scott/tiger@mfdb
    $ORACLE_HOME/bin/sqlplus scott/tiger
    $ORACLE_HOME/bin/sqlplus sys/change_on_install as sysdba
    $ORACLE_HOME/bin/sqlplus / as sysdba
    Alison

  • I need some help with AVI and IDX files please.

    Hello there,
    I've just been given a hard drive with a load of media on it that I need to work with in FCP.
    There's a folder with many .AVI clips, and each clip has an accompanying directory file with the extension .IDX
    The format of the AVI files is DV, 720x576, 48kHz.
    For the life of me, I can't get FCP to accept the media. Log and Transfer won't accept them, and if i bring in the AVI files in on their own using File>Import>Files... I get a message saying:
    Media Performance Warning
    It is highly recommended that you either recapture the media or use the Media manager to create new copies of the files to improve their performance for multi-stream playback.
    I can click 'OK' for this message and the media will appear in the browser, but If I place one of these AVI files on a new conformed sequence, the audio needs rendering. (Sequence settings correspond to media settings)
    I tried just changing the wrapper from AVI to MOV, thinking I could fool FCP into accepting them, but I get the same rejection.
    I thought the audio and video signals might be muxed, so I tried MPEG Streamclip to sort that out, but even MPEG Streamclip doesn't accept the media, saying : File open error: Can't find video or audio tracks.
    Could anybody advise me on how to get the most out of these media files please?
    Thanks in advance.
    James.
    Message was edited by: James M.
    Message was edited by: James M.

    yes. I tried transcoding in QT, but they still come in with the same audio rendering required. I'm a bit loath to convert them all though, as there are 1400 clips.
    It's not a huge problem, as they do play in FCP, but I'd like to sort out the audio rendering. I don't understand why it needs rendering as the media and sequence audio settings match, and it's not some weird format or anything, it's bog standard 48kHz stereo.

  • Newbee needs suggestions for a search and replace script

    I can't figure out this scripting stuff. I looked at the scripting guide I downloaded from adobe some time ago. I am not a programmer.
    I do not need a script that says "hello world."
    I need a script that will do the following:
    Search selected text from one point to another. let me explain.
    I create a table of contents in InDesign CS4. We separate our book sections by "section". So the TOC looks like:
    Section 1
    item one.... 1
    item two... 2-4
    item three... 5
    Section 2
    item one... 1-3
    item two... 4-5
    item three... 6
    and so forth.
    I then manually go in and change the TOC to:
    Section 1
    item one... 1 - 1
    item two... 1 - 2-4
    Section 2
    item one... 2 - 1-3
    item two... 2 - 4-5
    Where the page reference in the TOC contains the section prefix and the page number provides the page range (if more than one page). Should mention that when I create the TOC I use a place holder in the TOC style set up for the section prefix; that is, my TOC initially looks like:
    Section 1
    item one.... X - 1
    item two.... X - 2, etc. I then highlight a range and find/change for each range.
    So, the script would do the following:
    Look in selected text (the entire TOC) frame which at times spans two or three pages from Section 1 to Section 2:
    Change the "^t (tab before number) to "^t (section number)(space)(hyphen)(space)":
    And then look at next number (i.e "4") and change the previous end of previous line from "1" to "1-3"
    Then repeat for range from Section 2 to Section 3, etc.
    Currently, I do it manually. That is ok, but it would be great to have a script that would do this for me.
    Thanks in advance,
    RPP

    The last thing you need is a script.
    When you want to make your TOC, go to Pages, Numbering and Section Options, and put a section prefix in like 1- for each section (both 1 and 2 in your case). Click "Include Prefix When Numbering Pages".
    Then make your TOC.
    It will have all the section prefixes. ("1-1", "2-2-4", examples)
    Now just change the Numbering and Section Options BACK to your pre-TOC defaults. As long as  you don't update the TOC under Layout/Update TOC, your TOC text will contain the prefix, but your page numbers will look normal. If you have to change the text in the TOC for any reason, do it manually.
    Let me know if that works.
    Greg Ledger
    www.macproductionartist.wordpress.com

  • Help with Itunes and Windows ME please

    I have a Nano and use it with Windows XP with no problems. We purchased a 3rd generation Nano for my parents and their computer is several years old and uses Windows ME but the Itunes site says it is only for XP and Vista. What alternatives do I have other than to tell them to buy a new computer?

    Thats true but...
    Lets say you had the minamum requirments for me then you would need to upgrade the Hard Ware. XP is really cheap now so its worth the xtra bucks.

  • Search and replace with comma

    Hello All,
    I want some help. Please help me.
    I have comma delimited Data. When I’m converting Sting to Array, If two commas exists in between then its displaying “Zero” (because its array propriety ). Instead of that I want to display “NaN” .
    Please give me any idea to replace comma to NaN. I tried with Search and Replace but it’s not giving as I expected.
    Munna
    Solved!
    Go to Solution.

    Hello GerdW,
    Thanks you so much for your reply.
    I thought, instead of replacing trailing comma by NaN adding comma before string is more better (because to many string manipulations) But, it’s taking more execution time.
    Munna
    Attachments:
    Search and Replace.vi ‏415 KB

  • Search and replace string problems

    Hi to all,
    I have problem with Search and replace string function. It shows me a wrong Value (Number) from 15 to 100 is everything OK (15=0, 30=1, 45=2, 100=3), but after 100 ........
    Take look in VI and if you have any ideas post them please
    THX
    Igor 
    Attachments:
    indexing.vi ‏10 KB

    there will be no 15115 string, but 15 or 115 and 15 is 0, 115 is 4. Anyway, i have changed string input format and now its working THX for your help
    Attachments:
    indexing.vi ‏10 KB

  • JS InDesign Server CS2 - Search and Replace

    I am struggling to get a search and replace script to work on InDesign Server CS2.
    This works on my Desktop CS2:
    app.documents[0].search('xxx', false, false, 'yyy');
    but not through InDesign Server CS2.
    Can any one please help.
    Thanks
    Simon Kemp

    Thanks for all of the replies.
    This situation is that the company I work for has decided to consolidate some of the duties of our graphics departments.  People in one location will be dummying documents for people at another location.
    The paths to the images are UNC paths, which means they're pointing to different shares on different servers.  This cannot be changed.
    Also, the images at either location may not exist until days after the dumming process.
    During the dummying process, the application that's used to build the pages places empty ad boxes (placeholders) on the page.  The placeholders are text frames.
    I don't understand in what way, but the paths to the images are hidden inside the InDesign file.  From the users' standpoint, the placeholders simply display basic information about the ad (customer name, ad number, etc.) and hold the position for the images that will be placed later.
    It is not using script labels to apply the paths.
    So, this is why I describe the problem as needing to do a search and replace inside the InDesign file.
    As I mentioned before, I know this is doable.  I think I now see that the problem problem is figuring out how these hidden paths are being applied in the document.  My only thought was script labels, but this is not the case...

  • Search and Replace on master pages

    Is there a way to do Search and Replace on masterpages.
    Example: There are 30 files in a .book document.
    On those 20 files the header and footer must change.
    The header and footer are on the master pages.
    Can you p. e. change "Haeder1" to "Header1" with Search and Replace?
    Right now we do it on this way:
    Open all files in book
    Set view to Masterpage manually file per file (30 times).
    Search "Haeder1" and replace with "Header1" (option search in book)
    Is there a way to do it faster?
    Thanks in advance
    Sander Gheldof

    Thanks for your help...but the headers aren't variables...
    It may be that your solution is to bite the bullet today and do the page-by-page change of your headers to variables.
    System header variables can, for example, contain text from a paragraph style such as a level-[ 1 | 2 | 3...] heading. Or other values received from a FrameMaker named paragraph style.
    User-defined variables can also be used in headers and footers, although they can't be made to do the zippy automatic things system header/footer variables do...
    The essential point being that after doing it the hard way today, you may never need to do it again tomorrow. Or, alternatively, subsequent changes can be effected by changing the value of the variable and importing that into the desired target chapter files...
    Cheers & hope this helps,
    Riley

Maybe you are looking for