🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20403

Re: Dave Saunders' Running Heads Script

#20403
From: Peter Boctor
Date: Mon, 29 Jul 2002 17:28
60 lines
3857 bytes
Jon, 

 Interesting question, though. If a para starts on one page, then flows to the next, is it para -1 of the first page, para 1 of the second, or both?   

This is a trick question because from scripting, paragraphs don't belong to a page. :) 

 The problem I'd like to address is multiple empty paras at the end of the story. What I'd like to do in the last frame is tell the script "start with the last para; if that para doesn't have a 'word 1', then move up one para. Keep doing this until you find a 'word 1', then set myName to Word 1."   

There are many ways to do this. One is to walk through the paragraphs from the end to the front and return the first paragraph that has a word. Here is  some code that does this: 

tell application "InDesign 2.0.1"
     set myStory to object reference of story 1 of document 1
     tell me
          set theLastParagraph to findLastNonEmptyParagraph(myStory)
          display dialog (get contents of theLastParagraph)
     end tell
end tell

on findLastNonEmptyParagraph(theTarget)
     -- theTarget can be anything that contains paragraphs
     -- stories, text frames and cells are some examples
     tell application "InDesign 2.0.1"
          set paragraphCount to number of paragraphs of theTarget
          repeat with i from paragraphCount to 1 by -1
               if exists word 1 of object reference of paragraph i of theTarget then return object reference of paragraph i of theTarget
          end repeat
          -- if we get this far, then the target doesn't have any paragraphs with words
          display dialog "Couldn't find the last non empty paragraph!"
     end tell
end findLastNonEmptyParagraph 

 PS: Peter, how do you get your quoted scripts to not double space like mine do?   

I replace all the returns with <BR> tags. Of course I don't do this manually. Since I use an Applescript editor which is scriptable (Script Debugger, which I highly recommend http://www.latenightsw.com) <http://www.latenightsw.com)> I wrote the following script: 

tell application "Script Debugger" to set theSelection to selection of window 1
tell me to set theSelection to FindAndReplace(theSelection, tab, "     ")
tell me to set theSelection to FindAndReplace(theSelection, return, "<BR>")
set the clipboard to "<pre>" & theSelection & "</pre>"

on FindAndReplace(theText, replaceFrom, replaceTo)
     -- Set the text item delimiter to what we are looking for
     set {OldDelim, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {replaceFrom}}
     
     -- The text items are now sepearated
     set varList to theText's text items
     
     -- Set the text item delimiter to what we are replacing with
     set AppleScript's text item delimiters to replaceTo
     
     -- Coercing the selection to text will create a string with the text items and the replace with in between
     set theResult to varList as text
     
     set AppleScript's text item delimiters to OldDelim
     
     return theResult
     
end FindAndReplace 

-peter
Technical Details
Message-ID: <ef9de98.15@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!bnewspeer01.bru.ops.eu.uu.net!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef9de98.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,37e35bfe49790ac7
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-07-29 10:40:19 PST
From: "Peter Boctor" <peter.boctor@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!bnewspeer01.bru.ops.eu.uu.net!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Dave Saunders' Running Heads Script
Message-ID: <ef9de98.15@WebX.aaQKaf7vad4>
Date: Mon, 29 Jul 2002 10:28:32 -0700
References: <ef9de98.-1@WebX.aaQKaf7vad4>
Lines: 60
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit