Deleting Pages from end of Indesign CS3 document

I have an applescript that does some layout changes to an indesign document that results in there being blank unneeded pages at the end of my document. I want to delete any blank pages from the end of my document.

As each blank page still has a blank threaded text frame on it I originally tried to use the “end text frame” property to go to the last text frame and delete that page if the text frame was empty - I’d keep repeating this until the last text frame was empty, but i couldn’t work out how to do this.

So I have tried the script below which finds any empty text frames that are the width of the margins and then tries to delete the page. It finds the text frames, however it gets an error when it tries to delete the page. Any help is much appreciated! Thanks!

tell myIndesignDoc
set everyTextFrame to every text frame
repeat with thisTextFrame in everyTextFrame
set myColumnWidth to text column fixed width of text frame preferences of thisTextFrame
if contents of object reference of thisTextFrame is “” and myColumnWidth is greater than “111” and myColumnWidth is less than “112” then

				--I think The 2 lines below are flaky - only partly work; bascially need a way to delete the page
				set mypage to parent of myTextframe
				delete mypage
			end if
		end repeat
	end tell

Hi,

try this


tell application "Adobe InDesign CS3"
	set myIndesignDoc to document 1
	my deleteEmptyPages(myIndesignDoc)
end tell

on deleteEmptyPages(doc)
	tell application "Adobe InDesign CS3"
		tell doc
			set allPages to (get pages)
			repeat with onePage from (count allPages) to 1 by -1
				repeat with oneFrame in text frames of page onePage
					set myColumnWidth to text column fixed width of text frame preferences of oneFrame
					if contents of object reference of oneFrame is "" and myColumnWidth > "111" and myColumnWidth < "112" then
						delete page onePage
					else
						return
					end if
				end repeat
			end repeat
		end tell
	end tell
end deleteEmptyPages

Thanks Stefan - this worked beautifully :slight_smile:

Also thanks so much for the quick response, I’m new to Applescript and you’re help has been a real time saver for me!

All the best,

Lee