Deleting unused pages in template

Is there a script that can delete unused pages in a master document template in QuarkXpress 4.11?

There are only one or two actual pages in the document, but there are more pages listed in the document layout. I would like to remove the pages that are not being used in the template in order to reduce the file size of the document.

So basically, the script would need to check to see if the master spread is in use and if not delete it. Also could that be made into a scriptlet? Thanks for your help.

This was tested in Quark 6.5 sorry don’t have 4.0 but from memory its hasn’t changed

Get master’s used simple. Get master’s available simple. Find not used master’s simple. But deleting them hard.

tell application "QuarkXPress"
	activate
	tell document 1
		set MastersUsed to name of master spread of every page
	end tell
	tell master document 1
		show
		set MastersAvailable to name of every spread
		set NotUsed to {}
		repeat with i in MastersAvailable
			set i to i as string
			if MastersUsed does not contain i then
				copy i to the end of NotUsed
			end if
		end repeat
		if not NotUsed = {} then
			repeat with i in NotUsed
				set i to i as string
				delete (pages whose name contains i)
			end repeat
		end if
	end tell
	show document 1
	show page 1 of document 1
end tell

Works fine with Non-spreads, single page masters.

Now spreads do some strange thing. Create a doc with 4 masterpages spreads A,B,C,D add pages for A,C,D no B. run the script, it delete D not B

Run this script with show and delay as you go, doing backward so delete pages don’t effect the loop

tell application "QuarkXPress"
	activate
	tell document 1
		set MastersUsed to name of master spread of every page
	end tell
	tell master document 1
		show
		set MastersAvailable to name of every spread
		set NotUsed to {}
		repeat with i in MastersAvailable
			set i to i as string
			if MastersUsed does not contain i then
				copy i to the end of NotUsed
			end if
		end repeat
		if not NotUsed = {} then
			repeat with i from (count of MastersAvailable) to 1 by -1
				tell spread i
					show
					delay 3
					set TheName to name as string
					if NotUsed contains TheName then
						repeat with i from (count of pages) to 1 by -1
							show page i
							delete page i
							delay 3
						end repeat
					end if
				end tell
			end repeat
		end if
	end tell

Did you see it goes to B spread then to D spread when show B’s pages, wierd.

Havn’t had time to do a droplet

Have fun

Work it out, Quark delete page refers to the spread number, not the page number. So spread 2 {B} is page 2 even throw when you show it, it page 3.

I made it scan sub folder for fun, just drag your harddisk on it and the fix the problem harddisk wide. Mine didn’t say out of memory but I’ve got 4Gb.

I save it on first page and with preview.

on open of TheItems
	set FilesList to {}
	set FolderFiles to {}
	set QuarkFiles to {}
	repeat with TheTest in TheItems
		set TheTest to TheTest as alias
		set TheInfo to info for TheTest
		if folder of TheInfo then
			tell application "Finder"
				set FolderFiles to {}
				set TheCount to (count of files in entire contents of folder TheTest)
				if TheCount = 0 then
				else if TheCount = 1 then
					set FolderFiles to files in entire contents of folder TheTest as alias as list
				else
					set FolderFiles to files in entire contents of folder TheTest as alias list
				end if
				if not FolderFiles = {} then
					repeat with TheHit in FolderFiles
						set TheHit to TheHit as alias
						copy TheHit to the end of FilesList
					end repeat
				end if
			end tell
		else
			copy TheTest to the end of FilesList
		end if
	end repeat
	if not FilesList = {} then
		repeat with TestIfQuark in FilesList
			set TestIfQuark to TestIfQuark as alias
			set TheInfo to info for TestIfQuark
			if file type of TheInfo = "XPRJ" then
				copy TestIfQuark to the end of QuarkFiles
			end if
		end repeat
	end if
	
	if not QuarkFiles = {} then
		repeat with TheQuarkFile in QuarkFiles
			tell application "QuarkXPress"
				activate
				open TheQuarkFile
				tell document 1
					set MastersUsed to name of master spread of every page
				end tell
				tell master document 1
					show
					set MastersAvailable to name of every spread
					set NotUsed to {}
					repeat with i in MastersAvailable
						set i to i as string
						if MastersUsed does not contain i then
							copy i to the end of NotUsed
						end if
					end repeat
					if not NotUsed = {} then
						repeat with i from (count of MastersAvailable) to 1 by -1
							if NotUsed contains name of spread i then
								delete page i
							end if
						end repeat
					end if
				end tell
				tell document 1
					show
					show page 1
					save with include preview without template
					close
				end tell
			end tell
		end repeat
	else
		display dialog "There is No Quark files" buttons "Ok" default button 1
	end if
end open

have fun

Bevan www.applescript.co.nz