Quark - master pages

Hi

I’m trying to modify the content of the master page for a Quark document.

The part of the script which refers to the current box (tell current box) selected on the master page works fine, but when I then try and modify the master page as a whole (by adding in lines based on the leading information gleaned from the initial box) I get ‘QuarkXpress got an error: Can’t get line box.’ If I modify the script to run on, for example, page 1 it works fine.

I have read that scripting Quark master pages is tricky / no possible. Does anyone have any experience?


tell application "QuarkXPress"
	tell front document
		
		if not (exists current box) then error "A single text box must be selected."
		
		--- strip out returns at end of text
		tell current box
			tell story 1
				repeat until the last paragraph is not ""
					if it is not "" then
						delete last character
					else
						exit repeat
					end if
				end repeat
				
				--- count categories
				count (every text whose contents = (ASCII character 13))
				set numberofcats to result
				set numberofcats to (numberofcats + 1)
				
				--- calculate leading
				set categoryleading to (((212 - 52) / numberofcats) * 2.83475)
				set leading to categoryleading
			end tell
		end tell
	end tell
	
	tell front document
		--- put in dividing lines
		tell master document 1
			set startBounds to {59, 52 + (categoryleading / 2.83475), 247, 52 + (categoryleading / 2.83475)}
			repeat with i from 0 to (numberofcats - 2)
				make line box at beginning with properties {bounds:{(item 1 of startBounds), (item 2 of startBounds) + ((categoryleading / 2.83475) * i), (item 3 of startBounds), (item 4 of startBounds) + ((categoryleading / 2.83475) * i)}, width:0}
			end repeat
		end tell
		
	end tell
end tell

Thanks in advance

Mark

[Quark 6.5
OS X 10.4.8]

I haven’t scripted Quark in a while, since 4.1, but I believe that if you need to declare that you are working on the master pages. I’m not sure how to do this in the latest version of Quark, but it is probably the same since current page seems to return the last page of the document you were on even if you currently have a master page on the screen.

Thanks

Got there. The ‘master page’ statement has to be separate from, and not subordinate to, any ‘front document’ statement.


	tell application "QuarkXPress"

--- previous chunk defines all the variables

tell spread 1 of master document 1
		set startBounds to {59, 52 + (categoryleading / 2.83475), 247, 52 + (categoryleading / 2.83475)}
		repeat with i from 0 to (numberofcats - 2)
			make line box at beginning with properties {bounds:{(item 1 of startBounds), (item 2 of startBounds) + ((categoryleading / 2.83475) * i), (item 3 of startBounds), (item 4 of startBounds) + ((categoryleading / 2.83475) * i)}, width:0}
		end repeat
	end tell
end tell

Mark

Interesting. I had experimented with this after your first post but couldn’t figure it out. Never worked with the Master Page in scripting before. I did come up with this in case anyone finds it useful. This will check to see if you are currently showing the master page and do something (create a box in this case) on the master page if you are and if not, do it to the front document.

tell application "QuarkXPress"
	if masterdoc of front document then
		tell spread 1 of master document 1
			make new text box at beginning with properties {bounds:{"1\"", "2\"", "4\"", "5\""}, color:null}
		end tell
	else
		tell front document
			make new text box at beginning with properties {bounds:{"1\"", "2\"", "4\"", "5\""}, color:null}
		end tell
	end if
end tell

Browser: Safari 419.3
Operating System: Mac OS X (10.4)