🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20374

Re: Dave Saunders' Running Heads Script

#20374
From: Jay Fraser
Date: Fri, 26 Jul 2002 22:41
71 lines
4146 bytes
OK, here's the script I came up with: 
-- This script creates running heads for a directory, using the first word (a surname) 
-- of the first para and the last para on each page. Page numbers are added outboard 
-- of the names. The first text frame of the main body needs to be labeled "FirstFrame". 
-- Text frames of running heads on master pages need to be labeled "MasterHead" 
tell application "InDesign 2.0.1" 
	set active spread of active window to parent of page 1 of document 1 
	tell active spread of active window 
		-- checks for "FirstFrame" 
		try 
			set myTextFrame to text frame 1 whose label is "FirstFrame" 
		on error 
			activate 
			set dialogResult to display dialog "Can't find 'FirstFrame'. " & return & return & "Please select text frame of main story on first page and label it 'FirstFrame'." buttons "Whoops" with icon 0 
			if button returned of dialogResult = "Whoops" then error number -128 
		end try 
	end tell 
	-- uses the frames of the main body as a guide to each page 
	set theStory to object reference of parent story of myTextFrame 
	repeat with myCounter from 1 to count of text frames of theStory 
		set myTextFrame to text frame myCounter of theStory 
		set myPage to parent of myTextFrame 
		tell myPage 
			-- gets the first and last surnames 
			set myFirstName to word 1 of paragraph 1 of myTextFrame 
			set myLastPara to paragraph -1 of myTextFrame 
			try 
				word 1 of myLastPara 
			on error 
				set myLastPara to paragraph -2 of myTextFrame 
			end try 
			set myLastName to word 1 of myLastPara 
			-- This finds the text box for the running head 
			try 
				set myRunningHead to (text frame 1 whose label is "RunningHead") 
			on error 
				-- releases the running head text box from the master pages if needed 
				try 
					set myRunningHead to (master page item 1 whose label is "MasterHead") 
				on error 
					set dialogResult to display dialog "Can't find 'MasterHead'. " & return & return & "Please select text frames of running head on master pages and label them 'MasterHead'." buttons "Whoops" with icon 0 
					if button returned of dialogResult = "Whoops" then error number -128 
				end try 
				set label of myRunningHead to "RunningHead" 
			end try 
			-- checks if page number is even or odd, changes position of page number 
			if myCounter mod 2 = 0 then 
				set contents of myRunningHead to auto page number 
				set contents of insertion point -1 of myRunningHead to tab & myFirstName & " - " & myLastName 
			else 
				set contents of myRunningHead to tab & myFirstName & " - " & myLastName & tab 
				set contents of insertion point -1 of myRunningHead to auto page number 
			end if 
		end tell 
	end repeat 
end tell 
 
Actually, I'm kind of proud of it (even if 90% of it is borrowed from Dave) 

One question I have: when I'm trying to get the 1st word of the last para on the last frame, the script choked because there was an empty para right at the end. I put in a "try" so I could deal with one empty para, but I would like to put in a loop in case there are several empty paras. (I guess I could just delete the things, but then I wouldn't learn anything.) 

IOW, something like: 
 repeat until word 1 of myLastPara is not = 0 
set myLastPara to myLastPara + 1 
end repeat 

That didn't work, for a variety of reasons, but you get the idea? 

Thanks! 

Jay
Technical Details
Message-ID: <ef9de98.7@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.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-26 16:13:11 PST
From: "Jay Fraser" <jayfraser@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Dave Saunders' Running Heads Script
Message-ID: <ef9de98.7@WebX.aaQKaf7vad4>
Date: Fri, 26 Jul 2002 15:41:50 -0700
References: <ef9de98.-1@WebX.aaQKaf7vad4>
Lines: 92
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit