• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

find specific hyphenated word

Guide ,
Dec 02, 2014 Dec 02, 2014

Copy link to clipboard

Copied

hello,

is there a way to find all occurrences of one specific word, but only when it is hyphenated?

Thank you in advance

p.s I can see the answer(s) only tomorrow

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 03, 2014 Dec 03, 2014

Okay, that's clear. Here is a longer script that (1) prompts you for the word (it'll remember the last one used, or use any selected text), (2) search for hyphenated occurrences as before, and (3) if found, highlight the next case. It will search through the entire document and start in the position the text cursor is in. It will start searching in the 'current' story and if it doesn't find the word in there, it will check all other stories (i.e., unconnected textframes).

if (app.selection.lengt

...

Votes

Translate

Translate
Community Expert ,
Dec 02, 2014 Dec 02, 2014

Copy link to clipboard

Copied

Yes -- by making a list of all occurrences of that word (which is a built-in function), and then removing the ones that are not hyphenated (which is not, but pretty easy).

Note that finding multiple words is a pretty useless operation. Usually you are interested in locating the first (or next) occurrence, or you want to find them then and then do something. A potential problem, however, is that 'doing something' to an hyphenated word may change the running text, and so words that were earlier reported as 'not hyphenated' could be broken, and the reverse.

The following script will find all hyphenated occurrences of 'nonfunctional' ... and then do nothing with that information.

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "nonfunctional";

app.findChangeTextOptions.wholeWord = true;

list = app.activeDocument.findText();

for (i=list.length-1; i>=0; i--)

    if (list.lines.length < 2)

        list.splice(i,1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 02, 2014 Dec 02, 2014

Copy link to clipboard

Copied

Jongware,

Very interesting script. I am very sure it will have many possibilities.

IT is possible to use a list of words instead of only one?

Thanks for this piece.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2014 Dec 02, 2014

Copy link to clipboard

Copied

Put it in a loop. But its usefulness depends heavily on what you do with the words you find. Finding is okay, then having something automatically done not.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 02, 2014 Dec 02, 2014

Copy link to clipboard

Copied

hi jongware,

thanks a lot.

However I do something wrong: I copied and pasted youre script. I changed the word "nonfunctional" with one other word (hyphenated) and when I start the script don't happened nothing.

Where I wrong?

Thanks in advance

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Correct, and that's why I already said it would not 'do' anything after finding. But the script itself does work, and the variable list is filled with the found items; then the script stops. It's up to you to 'do' something with that list.

What do you want to do with the found text? Let me remind you again that something like changing the found text will not work the way one would hope! As soon as you change any text, (1) it will most likely invalidate the rest of the 'found' list, because this stores text positions -- and when text re-formats, the earlier found positions may not be valid anymore; and (2) if the text re-formats, words that are in the list as "hyphenated" may reflow and not be hyphenated any longer, as well as words that are not in the list may be hyphenated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Jong,

Your script could be magic and irreplaceable in cases where some partitions originate big problems.

It is possible to change the finding of a word for an expression that finds hyphen-culo?

For example, in spanish those words composed by the termination culo (culos) ā€“that is literally ass/assesā€“ are seen very bad when the hyphen shows it and the costume is fix them.

Without your script checking these words could be almost impossible as the termination culo/s is part of tens of thousands of words.

It is interesting this point as I am sure this termination is the only one that creates this alert.


70 copy.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Camilo, I think you could use a GREP style for that! Create a char style that has only No Break set, and apply it to

\wculos?\b

-- all words that end with 'culo' or 'culos' (good thing the Dirty Word Nanny Filter only complains about English words ) . The No Break will prevent breaking just before this part, but it will still break on other allowed positions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Jong,

Yes, it works although frequency for this item is very high.

Visual control seems better as long words could be need breaking sometimes.

Thanks.

Screen Shot 2014-12-03 at 07.54.32.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi jongware,

For me is important that the script just find the hyphenated word, but when I start the script doesn't find nothing, although the hyphenated word exist.

I have one file in indesign that has 600 pages and I have seen that one abbreviation sometimes hyphenated.

Now, I don't want change all occurrences with "find" that word and "change" in the same word but not hyphenated, because the text in this case could moves without my control.

I would like simply to find that word only when it is hyphenated and change manually with controll if the text moves or not.

Thank you in advance

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

hi camilo umana,

very interesting

thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Okay, that's clear. Here is a longer script that (1) prompts you for the word (it'll remember the last one used, or use any selected text), (2) search for hyphenated occurrences as before, and (3) if found, highlight the next case. It will search through the entire document and start in the position the text cursor is in. It will start searching in the 'current' story and if it doesn't find the word in there, it will check all other stories (i.e., unconnected textframes).

if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].contents.length > 0)

   word = app.selection[0].contents;

if (word == undefined)

    word = '';

wordToFind = prompt ("Find what", word);

if (wordToFind)

{

    app.findTextPreferences = app.changeTextPreferences = null;

    app.findTextPreferences.findWhat = wordToFind;

    app.findChangeTextOptions.wholeWord = true;

    list = app.activeDocument.findText();

    for (i=list.length-1; i>=0; i--)

        if (list.lines.length < 2)

            list.splice(i,1);

    // found anything?

    if (list.length == 0)

        alert ("Cannot find match");

    else

    {

        // anything selected?

        if (app.selection.length == 0 || !(app.selection[0].hasOwnProperty("insertionPoints")))

        {

            // no, pick first one

            list[0].select();

            app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;

        } else

        {

            // locate next after current position

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

            {

                if (list.parentStory == app.selection[0].parentStory)

                {

                    if (list.insertionPoints[0].index > app.selection[0].insertionPoints[0].index)

                    {

                        list.select();

                        app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;

                        break;

                    }

                }

            }

            if (i==list.length)

            {

                // not in this story; anywhere else?

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

                {

                    if (list.parentStory != app.selection[0].parentStory)

                    {

                        list.select();

                        app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;

                        break;

                    }

                }

                if (i==list.length)

                    alert ("Cannot find match");

            }

        }

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

This script is exactly what I needed!

Thank you very much jongware

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi. I understand the script asks for a word?

  1. if (word == undefined) 
  2.     word = ''
  3. wordToFind = prompt ("Find what", word); 

JONG.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hmm ... I'm a bit busy now so can't check -- and this would require restarting ID a couple of times. I thought 'undefined' values (i.e., not earlier defined) had the contents "undefined". I think I did not notice because while writing "word' always was defined because of previous runs of the same script. Maybe you can add a try..catch around this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Jong, something is curious  as premio_oscar admitted the script is working.

Yes, of course I will check.

Thanks for your time.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

hi camilo umana,

I select a word and than start the script.

in this way the script doesn't give any error message.

If I don't select nothing and start the script then I have the same error message as your.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Premio,

Thanks.

You may find P. Kahrel's scripts mentioned before also very interesting.

For example, you get in a whistle a list like this:

Kaka_nia

illu_sion

after_ward

kill_ings

with_in

cul_tivated

haphaz_ard

uni_fying

k2.jpg

Modernism: Representations of National Culture - The man without qualities - Central European Univer...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

LATEST

Thank you camilo for the Kahrel's script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines