Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Selected text formatting

Return to Member Forum

  • Author
    Posts
    • #61709
      Harry Thomas
      Member

      I searched for this, but perhaps I'm not using the correct syntax. Anyway, I need a simple solution.

      I would like to select/highlight a section of text, i.e.: a film name, and place opening and closing quotes around it. What is the best way to accomplish this? I would think it would be a GREP thing, but I didn't see anything on it in the Lynda.com tutorial (haven't completed it yet, but the headers give no indication).

      Thank you,

      Harry Thomas

    • #61711

      It can be done with a GREP replace: search for

      .+

      and replace with

      “$0”

      In essence, it finds “everything” and then replaces this with the found text, surrounded by double quotes. But you have to remind yourself to make sure it uses “Selection” in the GREP replace dialog every time. Otherwise you will get double quotes around 'everything' (depending what on the search scope says).

      A better way is to use a mini-javascript that first checks if you have a valid selection and only if so inserts the quotes for you. ( I went a little nuts here, loads of extra functionality :) )

      //DESCRIPTION:Add Quotes around text selection
      // Remove next line for CS3 or older!
      app.doScript(function() {
      if (app.documents.length != 0 && app.selection != 0 && app.selection[0].hasOwnProperty(“baseline”))
      {
      sel = app.selection[0];
      sel.insertionPoints[0].contents = sel.insertionPoints[-1].contents = '”';
      app.select (sel.characters[0],SelectionOptions.ADD_TO);
      }
      // Remove next line for CS3 or older!
      }, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Add Quotes');

      You can save this script in your Scripts folder and then use the Keyboard Shortcut Editor to assign a hotkey combo to it.

    • #61714
      Harry Thomas
      Member

      Your Javascript worked great. Thank you very much!

    • #61753
      gamouning
      Member

      Jongware,

      I need to do something similiar with GREP. What I'd like to do is select text between a specfic paragraph style. And it's important to use the Apply Next option. Can you tell me if this is possible?

      Thanks,
      Greg

    • #61757

      What does it mean to “select text between a specific paragraph style”?

      Both my suggested GREP and the script work on a selection, it doesn't actually sound to me like this is “something similar”.

    • #61760
      gamouning
      Member

      Hi Jongware,

      Sorry perhaps providing an example will be more helpful. Below is a sample of enties:

      Name
      Spouse
      Address;City, State Zip;Phone
      Email
      Name
      Seasonal Address;City, Country
      Name
      Name
      Spouse
      Address;City, State Zip;Phone

      I am putting together an Alumni Class Directory containing names, addresses, phone numbers and other information. There are over 700 etnries and each entry begins with a paragraph style called “Name”. The information that follows has a variety of paragraph styles assigned to them. I want to select text starting with the “Name” style including all subsequent text prior to the next “Name” style. Once selected I wish to use a new Paragraph style with Apply Next.

      It is important to note, some entries will be incomplete and might only contain a Name.

      Please let me know if this explanation is more clearly stated.

      Regards,
      Greg

    • #61765

      I still fail to see the similarity to the original post, but you could try a Single-line GREP:

      (?s)^Name.+?(?=rName)

      Not sure if it works though.

    • #61766
      gamouning
      Member

      Hi Jongware,

      The only similiarity is that the GREP “.+” appears to select a complete paragraph. I wish to know if there is anyway to create a GREP that will select multiple paragraphs in relation to a specfic paragraph style. I will use my previous example, and add paragraph styles in brackets:

      [parastyle1]Name[parastyle1]
      [parastyle2]Spouse[parastyle2]
      [parastyle3]Address;City, State Zip;Phone[parastyle3]
      [parastyle4]Email[parastyle4]
      [parastyle1]Name[parastyle1]
      [parastyle3]Seasonal Address;City, Country[parastyle3]
      [parastyle1]Name[parastyle1]
      [parastyle1]Name[parastyle1]
      [parastyle2]Spouse[parastyle2]
      [parastyle3]Address;City, State Zip;Phone[parastyle3]

      In the first entry, I want to select text that starts with [parastyle1] and the selections ends after [paprastyle4].
      In the second entry, I want to select text that starts with [parastyle1] and the selections ends after [paprastyle3].
      In the third entry, I want to select text that starts with [parastyle1] and the selections ends after [paprastyle1].
      In the fourth entry, I want to select text that starts with [parastyle1] and the selections ends after [paprastyle3].

      Does that help?

      -Greg

    • #61773

      It's not possible with GREP, this needs a script.

      Unfortunately, the script has to work with the entire contents of the active story — I was foolish enough to test on my current working document (>340 pages) and it took so long to run I decided to kill off InDesign. The reason it has to “see” the entire story is because you cannot access any random paragraph at will; the Document Object Model (which is the foundation on which scripts run) must “process” an entire story before you can check the style of any “next” paragraph.

      That said: this script runs correctly on a fairly short story; it will select the paragraph containing the cursor, and then any next paragraphs as long as that's not in the same style as it started with.

      // Where am I?
      currentParagraph = app.selection[0].paragraphs[0];
      // Where do I start?
      selectedParagraphStyle = currentParagraph.appliedParagraphStyle;
      // Okay — select this one
      while (1)
      {
      // Okay — select this one
      app.select(currentParagraph, SelectionOptions.ADD_TO);
      // Check next
      nextParagraph = currentParagraph.characters.nextItem(currentParagraph.characters.item(-1));
      if (!nextParagraph.isValid || nextParagraph.appliedParagraphStyle == selectedParagraphStyle)
      break;
      currentParagraph = nextParagraph.paragraphs[0];
      }

    • #61775
      gamouning
      Member

      Thank you very much, I'll give this script a try. :-)

Viewing 9 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads