• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to select found text

Explorer ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

Hello,
I need to find some text in a document. I do not want to change it, I just want it selected. Why does the following not work?

//This works, placing the word in the find dialog box.
app.findTextPreferences.findWhat = "text";

//Should not this highlight (select) the word "text"?
app.activeDocument.findText();

What I eventually want to do is to find Object Styles and fill in the text boxes temporarily with some color. This helps in checking 400 pages quickly to see if the correct styles have been used.

But first I have to figure out this simple problem.

Thanks,
Tom
TOPICS
Scripting

Views

2.1K

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 Beginner ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

in VB:

myDoc.findTextPreferences.findWhat = "text"
set myFounded = mydoc.activeDocument.findText()
call myindi.select(myFounded.item(1))

I hope you can translate it to JS

robin

--
www.adobescripts.com

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 ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

// Clear the find dialog -- you never know what's left there
app.findTextPreferences = null;
app.findTextPreferences.findWhat = "text";
myFound = app.activeDocument.findText();

myFound is an array of everything that was found. To select the first item (assuming that any were found), do

myFound[0].select();

And to display the page/spread on which the first item was found, use this:

app.activeWindow.activeSpread = myFound[0].parentTextFrames[0].parent.parent;

Peter

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 ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

However, it is rare that a script needs to select found text. It is more common that you need the reference (myFound[0]) to operate upon, e.g., apply a character style.

Dave

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 ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

Fair point. But I was prejudiced by a script I did recently which needed to show found items in their spread.

Peter

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 ,
Apr 20, 2008 Apr 20, 2008

Copy link to clipboard

Copied

Oh I've written them too. One of the annoying things about InDesign is that it makes it hard for you to actually see what has just been found -- this is even more annoying with Find Font, which is a modal dialog so you can't run a script without first closing the dialog.

I have a script I call BetterViewAfterFind who's sole purpose is to help locate the current text selection:
//DESCRIPTION: A Better View after Find


showIt();

function showIt(theObj) {
if (arguments.length > 0) {
// Select object, turn to page and center it in the window
app.select(theObj);
}
// Note: if no object is passed and there is no selection the current page
// will be centered in the window at whatever zoom is being used
var myZoom = app.activeWindow.zoomPercentage;
app.activeWindow.zoom(ZoomOptions.showPasteboard);
app.activeWindow.zoomPercentage = myZoom;
}
The behavior of the function is sufficiently unusual that I wrote myself a note so I wouldn't be tempted rewrite the script (which I nearly did until I stopped and read the note).

Dave

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 ,
Apr 20, 2008 Apr 20, 2008

Copy link to clipboard

Copied

Nice one.

Peter

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
Explorer ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Dear Dave and Peter,

Thanks much, your solution works. But could you please explain a bit of the code:

app.activeWindow.activeSpread = myFound[0].parentTextFrames[0].parent.parent;

I can find no explanation in Adobes Scripting Guide: JavaScript for activeSpread. Also, why is it necessary to use parent.parent?

Dave says it is rare that one would need to select found text, one usually wants to effect some change to the found text. That is true.

What I would like is to change the background color of the found text so that one could then look at the whole document to see where this text is. If it is just selected, one slip of the wrist and the selection goes away (or worse, is deleted). If the background color were temporarily changed, it would have to be consciously changed back to no color by invoking more script.

Sohow come this doesnt change the background color?:

myFound[0].fillColor = app.activeDocument.swatches.item("a color in swatches panel");

I am hoping that once I understand this, Ill be able to search for Object Styles. Ive tried writing a script for this, but have become stymied. But that is a topic for another string.

Thanks,
Tom

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

There is no such thing as "background color" -- it's as simple as that. The fill color of the found text is the color of the text itself.

You can simulate a background color by making a custom underline and applying it -- either locally in the script or through a character style -- my choice would be a character style which I would probably set-up in the document manually and then just apply it:

myFound[0].appliedCharacterStyle = "MyBGcolor";

As for your parent.parent question:

The parentTextFrame of the text is a text frame which sits on a page (i.e., the text frame's parent) which in turn lives in a spread (i.e., the page's parent).

Dave

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Bear in mind that the search you're doing returns an array of all instances of the found text. We've focused on myFound[0] because you wanted to select text, but you can only select one piece of text.

On the other hand, with a search, you can apply a character style to every instance in one swell foop.

Dave

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Remind me -- is that a spoonerism or a malapropism?

Peter

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Spoonerism.

Dave

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Fortunately these messages stay edible for a while for the original author.

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 ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

Took me a while, but that, of course, is a Malapropism. Well done.

Dave

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 ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

Thanks Dave-- For a non-native speaker like me, it takes some blunt sweaty ears to come up with these.

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 ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

There's no stopping you! I was braining my wreck for a decent example, but like you, I'm a non-native and and they don't come easy.

Peter

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
Explorer ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

There's nothing I enjoy more than a ride round the park on a well boiled icicle.

My mother referred to the small chickens we'd sometimes have for dinner as "Gamish Corn Hens." Her verbal tics and my great love for Walt Kelly's "Pogo" resulted in a brain that delights in scrambling words in various ways. It's a wonder I can write in "normal" English at all.

Thanks,

Rival Monk Tavern

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 ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

And "Rival Monk Tavern" is an anagram of ...?

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
Explorer ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

Hi Peter,

It's an anagram of "Olav Martin Kvern." It's the best one I've found--or at least the one most metaphorically descriptive of my character.

Thanks,

Ole

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 Beginner ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

I guess that could also be

Viral Monk Tavern...

Bob

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 Beginner ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

Had some fun with: http://wordsmith.org/anagram/

Here's some others for Ole:

Varmint Rank Love
Mavin Rank Revolt

And a couple for me:

Scrubber Tucker Toy
Scrubby Creek Trout
Scrubby Trucker Toe
Tubby Trucker Score

with mine, there were some that can't be shown (they start with Rubber or Rubbery....) ;0)

Bob

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
Explorer ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

LATEST
Hi Bob,

I've already rejected those, and am sticking with Rival Monk Tavern. I spent a long time trying to get something with both "Varmint" and "Vole" in it to work, though.:-)

Thanks,

Ole

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