Article View: adobe.scripting.indesign
Article #20516Insert Character in middle of selection
From: Jay Fraser
Date: Mon, 08 Jul 2002 17:52
Date: Mon, 08 Jul 2002 17:52
52 lines
2287 bytes
2287 bytes
I'm working on a telephone book which has 8-digit numbers. The file I rec'd has all 8 digits in a contiguous row, but I needed to insert a space in the middle, i.e. change from
12345678
to
1234 5678
After some trial and error I came up with this:
tell application "InDesign 2.0"
if (count documents) > 0 then
set find preferences to nothing
set change preferences to nothing
set myDocument to active document
tell myDocument
set myFoundItems to {}
set myFoundItems to search myDocument with find attributes {whole word:true, applied character style:character style "Number" of myDocument, find text:"^9^9^9^9^9^9^9^9"}
try
myFoundItems
on error
set myFoundItems to {}
end try
if (count myFoundItems) > 0 then
repeat with myCounter from (count myFoundItems) to 1 by -1
set myFoundItem to item myCounter of myFoundItems
set contents of insertion point -5 of myFoundItem to space
end repeat
else
activate
display dialog "Specified Text Not Found"
end if
end tell
else
activate
display dialog "Please open a document and try again."
end if
end tell
My questions are:
1) Can somebody explain the myCountItems routine? I've just cut-&-pasted it, but I don't understand it.
2) Why "insertion point -5"? I found it though trial and error, but I don't understand the logic.
3) Is there a more elegant way to do my error-checking?
Thanks to all previous posters from whom I borrowed in order to do this.
Jay
Technical Details
Message-ID:
<ef98891.-1@WebX.aaQKaf7vad4>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,943e1fd1b0f09137,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-07-08 11:08:23 PST From: "Jay Fraser" <jayfraser@yahoo.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Insert Character in middle of selection Message-ID: <ef98891.-1@WebX.aaQKaf7vad4> Date: Mon, 8 Jul 2002 10:52:19 -0700 Lines: 59 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit