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

Dealing with failed search

Participant ,
Jan 28, 2003 Jan 28, 2003

Copy link to clipboard

Copied

What is the best way to detect that a search has failed to find anything?

I've been using:

set find preferences to nothing
set change preferences to nothing
repeat
set myResult to search myStory for "^p^p" replacing with "^p"
try
get myResult
on error
exit repeat
end try
end repeat

But I'm sometime crashing ID 2.0.2 using this technique (although I can't reproduce it in trivial documents).

The problem is that you can't test myResult because it becomes undefined if nothing is found.
TOPICS
Scripting

Views

544

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 ,
Jan 28, 2003 Jan 28, 2003

Copy link to clipboard

Copied

I still am unable to reproduce this problem with a simple document, but having imported a four page rtf document and then running:

tell application "InDesign 2.0.2"
set find preferences to nothing
set change preferences to nothiing
set mystory to parent story of selection
search mystory for "^p" replacing with "^p^p"
search mystory for " ^p" replacing with "^p"
search mystory for "^p^p" replacing with "^p"
end tell

I get a crash every time on the third search. (Would that the first and third were unnecessary, but the styles get screwed up if you don't do that.)

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 ,
Jan 28, 2003 Jan 28, 2003

Copy link to clipboard

Copied

One more point of clarification: the third search does not fail if I comment out the first two. It only fails if it follows the previous two. Note also that in the document in question, the second one actually does nothing because there are no instances of " ^p".

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 ,
Jan 28, 2003 Jan 28, 2003

Copy link to clipboard

Copied

Does setting the fill color of Find Preferences work? It doesn't for me in this sequence:

set find preferences to nothing
set change preferences to nothing
set point size of find preferences to 16
set fill color of find preferences to swatch "[Black]" of document 1
set applied paragraph style of change preferences to paragraph style of "LSTITLE" of document 1
search myStory for "" replacing with ""

This is changing all the 16 point text to LSTITLE, regardless of color.

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 ,
Jan 28, 2003 Jan 28, 2003

Copy link to clipboard

Copied

I just realized I've not been using the correct syntax!

It should be 'search in myStory" not just 'search myStory'

However, that doesn't change the crash problem.

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
New Here ,
Jan 29, 2003 Jan 29, 2003

Copy link to clipboard

Copied

Dave --

I haven't had a problem w/ system crashes, but I have experienced inconsistent results if I try to string several searches one-after-the-other in a script. I eventually broke them out into separate scripts, & manually run them, w/ no problem. A little more hassle, but trying to de-bug the sucker was killing me.

I don't know if you can get a separate script to run the scripts?

Sorry I don't have anything better, but I felt sorry for you, sitting in your corner talking to yourself. [grin]

Jay

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 ,
Jan 29, 2003 Jan 29, 2003

Copy link to clipboard

Copied

Jay,

Turns out that use a single list of Find Attributes as part of the Search statement is superior to setting the individual preferences.

Mind you, I found this out after I had finagled the preferences approach into working for me.

Thanks for caring.

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 ,
Feb 09, 2003 Feb 09, 2003

Copy link to clipboard

Copied

As an update, I've discovered that after importing said four-page rtf file (I actually have 30-some to process), running:

search in myStory for "^p^p" replacing with "^p"

crashes ID 2 every time. So, it occurred to me that I could nonetheless do this:

repeat
set myResult to search in myStory for "^p^p"
try
get myResult
on error
-- there weren't any
exit repeat
end try
repeat with n from count of myResult to 1 by -1
set contents of item n of myResult to return
end repeat
end repeat

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
Guest
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

Thanks a lot

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 ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

LATEST

Wow. A thread from the year 2003 dealing with InDesign version 2 !

 

Regards,
Uwe Laubender

( ACP )

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