Tuesday, December 12, 2017

#1 2017-09-13 08:18:01 pm

nellbern
Member
Registered: 2007-01-16
Posts: 120

Indesign Find text string & display alert

I need to find a specific text string in the current active document & if it doesn't exist then display an alert. The script below works in some documents but not all of them. Sometimes I get this error when I have more than one document open or when the file contains more than 1 page:
Can’t make {text from character 2 to character 11 of story id 274567 of document id 63 of application "Adobe InDesign CS6", text from character 2 to character 11 of story id 274648 of document id 63 of application "Adobe InDesign CS6"} into type Unicode text.

What possible can be wrong? hmm


Applescript:

set findThis to "XX28.18"
tell application "Adobe InDesign CS6"
   activate
   
   --clear fields ...
   set find text preferences to nothing
   
   -- set find options
   set case sensitive of find change text options to true
   set whole word of find change text options to true
   
   set include hidden layers of find change text options to false
   set include locked layers for find of find change text options to false
   set include locked stories for find of find change text options to false
   
   set find what of find text preferences to findThis -- load string into the 'Find'
   tell document 1
       set pageCode to find text findThis
       
       if pageCode is not in findThis then
           display alert "XX28.18 not found"
       end if    
       
   end tell
   set find text preferences to nothing
end tell

Model: iMac (Retina 5K, 27-inch, Late 2015)
AppleScript: 2.8.1 (183.1)
Browser: Safari 537.36
Operating System: Mac OS X (10.11.6)


Filed under: find text string

Offline

 

#2 2017-09-14 08:33:35 am

TecNik
Member
From:: Applescript-Leeds-England-UK
Registered: 2003-04-02
Posts: 560
Website

Re: Indesign Find text string & display alert

Hi There,

The code below seems to work ok in InDesign CC 2015.

HTH

Applescript:


set findThis to "XX28.18"

tell application "Adobe InDesign CC 2015"
   
   activate
   
   --clear fields ...
   set find text preferences to nothing
   
   -- set find options
   set case sensitive of find change text options to true
   set whole word of find change text options to true
   
   set include hidden layers of find change text options to false
   set include locked layers for find of find change text options to false
   set include locked stories for find of find change text options to false
   
   set find what of find text preferences to findThis
   
   set findTextResult to find text front document
   
   if (count of findTextResult) is 0 then
       display alert "Nothing found!"
   else
       set alertText to ((count of findTextResult) & " instance(s) of " & findThis & " found.") as string
       display alert alertText
   end if
   
   set find text preferences to nothing
   
end tell

Last edited by TecNik (2017-09-15 07:33:46 am)

Offline

 

#3 2017-09-14 09:21:33 am

nellbern
Member
Registered: 2007-01-16
Posts: 120

Re: Indesign Find text string & display alert

That is perfect big_smile thanks. Can I ask why the command count is needed. I just need to find a text string & not count the times found in the document. I'm still learning

Last edited by nellbern (2017-09-14 09:22:21 am)

Offline

 

#4 2017-09-14 10:50:17 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 772

Re: Indesign Find text string & display alert

Hi. Using count is a valid solution but isn't strictly necessary. The explanation for what went wrong is that find returns an object reference or group of same. When there is one, you can ask for equality to a comparator, and ID obliges by automatically coercing it to text; when there are multiple references, it doesn't.

Offline

 

#5 2017-09-14 07:36:19 pm

nellbern
Member
Registered: 2007-01-16
Posts: 120

Re: Indesign Find text string & display alert

Ok thanks Marc & TecNik

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)