Execution of script disables undo command in QuarkXpress

I have been working in a script that does various things with text boxes in QuarkXpress 10.

Recently I realized that after executing my script, the undo command appears grayed out. If I restart QuarkXpress, undo command is restored.

I started disabling parts of my script, which I suspect could cause this. Then I changed syntaxis in some lines to do same thing in multiple steps. I can’t find what is causing this.

Any kind soul who can take the time to check my script and tell me what I’m doing wrong?
Thanks in advance for your help.

So this is the script (sorry about my programming, I’m just starting).


set vers to "Folios Catálogo 1.4b3"
tell application "QuarkXPress"
	activate
	set numberProjects to count of projects -- count of open projects
	set revList to {} -- list of files with errors
	set theMessage to "" -- preparing variable to receive revList
	with timeout of 500000 seconds
		if numberProjects is 0 then -- verify if there are open files
			beep
			display dialog "No hay ningún archivo abierto. Por favor abrir los archivos a procesar." buttons {"Ok"} default button 1 with icon 2 with title vers
			return
		else if numberProjects is 1 then
			display dialog "Se insertarán los números de página en 1 archivo." & return & "¿Continuar?" with icon 1 with title vers
		else
			display dialog "Se insertarán los números de página en " & numberProjects & " archivos." & return & "¿Continuar?" with icon 1 with title vers
		end if
	end timeout
	
	set openProjectList to name of every project -- create list of names of all open projects
	repeat with theProject in openProjectList -- repeat with each item of the list
		show document theProject
		tell document theProject
			set view scale to "200%"
			set horizontal measure to millimeters
			set vertical measure to millimeters
			set leftExists to 0 -- flag  left folio box existence
			set rightExists to 0 -- flag right folio box existence
			set leftDup to 0 -- flag left box duplicates
			set rightDup to 0 -- flag right box duplicated
			set nameOfDoc to name -- stores current document name
			set listOfBoxes to every text box
			-- disabled for testing **********************
			(*
			try
				set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
				set theFolios to text item 1 of nameOfDoc
				set AppleScript's text item delimiters to "-"
				set folioLeft to (text item 1 of theFolios) - "0"
				set folioRight to (text item 2 of theFolios) - "0"
				set AppleScript's text item delimiters to atid
			on error errMsg
				display dialog "El archivo \"" & theProject & "\" tiene un nombre no standard o no es una página interior." & return & "Corregir el nombre o cerrar el archivo." & return & return & "(" & errMsg & ")" buttons {"Ok"} default button 1 with icon 0 with title vers
				return
			end try
			*)
			set folioLeft to "00" --  just for testing
			set folioRight to "00" -- just for testing
			repeat with thisBox in listOfBoxes
				set thisBoxBounds to bounds of thisBox as list
				-- En QuarkXpress T=Y , L=X , B=Y+H , R=X+W
				set {T, L, B, R} to {(item 1 of thisBoxBounds coerce to real) as integer, (item 2 of thisBoxBounds coerce to real) as integer, (item 3 of thisBoxBounds coerce to real) as integer, (item 4 of thisBoxBounds coerce to real) as integer, story 1 of thisBox}
				if T > 220 and L < 9 and R < 26 then
					show thisBox
					set story 1 of thisBox to folioLeft -- Insert left folio number into the box
					set bounds of thisBox to {"223 mm", "7 mm", "227 mm", "17 mm"} -- Resize folio text box with Pre Press specs
					set leftExists to folioLeft -- Apply initial value to leftExists to avoid 0
					move thisBox to the front
					set leftDup to leftDup + 1
				else if T > 220 and L > 153 and R < 170 then
					-- show thisBox
					set story 1 of thisBox to folioRight -- Insert right folio number into the box
					set bounds of thisBox to {"223 mm", "155 mm", "227 mm", "165 mm"} -- Resize folio text box with Pre Press specs
					set rightExists to folioRight -- Apply initial value to rightExists to avoid 0
					move thisBox to the front
					set rightDup to rightDup + 1
				end if
			end repeat
		end tell
		if leftExists is 0 and rightExists is not 0 then -- if there is no left folio box
			tell document theProject
				set view scale to fit spread in window
			end tell
			with timeout of 500000 seconds
				display dialog "El archivo \"" & theProject & "\" no tiene folio izquierdo." & return & "¿Crear el folio izquierdo?" buttons {"Salir", "Ignorar", "Crear"} default button 3 with icon 2 with title vers
			end timeout
			if result = {button returned:"Ignorar"} then
			else if result = {button returned:"Crear"} then
				tell layer "Default" of page 1 of front document
					-- {top position, left position, bottom position, right position} or {Y,X,Y+H,X+W}
					make new text box at beginning with properties {bounds:{"223 mm", "7 mm", "227 mm", "17 mm"}, name:"leftBox", runaround:none runaround}
				end tell
				set story 1 of text box "leftBox" of page 1 of front document to folioLeft
				set font of story 1 of text box "leftBox" of page 1 of front document to "Trade Gothic LT Std Light"
				set size of story 1 of text box "leftBox" of page 1 of front document to 7
				set color of story 1 of text box "leftBox" of page 1 of front document to "Magenta"
				set justification of every paragraph of text box "leftBox" of page 1 of front document to left justified
			else if result = {button returned:"Salir"} then
				if theMessage is "" then
					set the clipboard to ""
					return
				else
					set the clipboard to "Spreads con cajas para folio duplicadas: " & return & theMessage
					return
				end if
			end if
			
		else if leftExists is not 0 and rightExists is 0 then -- if there is no right folio box
			tell document theProject
				set view scale to fit spread in window
			end tell
			with timeout of 500000 seconds
				display dialog "El archivo \"" & theProject & "\" no tiene folio  derecho." & return & "¿Crear el folio derecho?" buttons {"Salir", "Ignorar", "Crear"} default button 3 with icon 2 with title vers
			end timeout
			if result = {button returned:"Ignorar"} then
			else if result = {button returned:"Crear"} then
				tell layer "Default" of page 2 of front document
					make new text box at beginning with properties {bounds:{"223 mm", "155 mm", "227 mm", "165 mm"}, name:"rightBox", runaround:none runaround}
				end tell
				set story 1 of text box "rightBox" of page 2 of front document to folioRight
				set font of story 1 of text box "rightBox" of page 2 of front document to "Trade Gothic LT Std Light"
				set size of story 1 of text box "rightBox" of page 2 of front document to 7
				set color of story 1 of text box "rightBox" of page 2 of front document to "Magenta"
				set justification of every paragraph of text box "rightBox" of page 2 of front document to right justified
			else if result = {button returned:"Salir"} then
				if theMessage is "" then
					set the clipboard to ""
					return
				else
					set the clipboard to "Spreads con cajas para folio duplicadas: " & return & theMessage
					return
				end if
				return
			end if
			
		else if leftExists is 0 and rightExists is 0 then --  if there is no any folio box
			tell document theProject
				set view scale to fit spread in window
			end tell
			with timeout of 500000 seconds
				display dialog "El archivo \"" & theProject & "\" no tiene cajas de texto para folios." & return & "¿Crear los folios?" buttons {"Salir", "Ignorar", "Crear"} default button 3 with icon 2 with title vers
			end timeout
			if result = {button returned:"Ignorar"} then
			else if result = {button returned:"Crear"} then
				tell layer "Default" of page 1 of front document
					make new text box at beginning with properties {bounds:{"223 mm", "7 mm", "227 mm", "17 mm"}, name:"leftBox", runaround:none runaround}
				end tell
				set story 1 of text box "leftBox" of page 1 of front document to folioLeft
				set font of story 1 of text box "leftBox" of page 1 of front document to "Trade Gothic LT Std Light"
				set size of story 1 of text box "leftBox" of page 1 of front document to 7
				set color of story 1 of text box "leftBox" of page 1 of front document to "Magenta"
				set justification of every paragraph of text box "leftBox" of page 1 of front document to left justified
				
				tell layer "Default" of page 2 of front document
					make new text box at beginning with properties {bounds:{"223 mm", "155 mm", "227 mm", "165 mm"}, name:"rightBox", runaround:none runaround}
				end tell
				set story 1 of text box "rightBox" of page 2 of front document to folioRight
				set font of story 1 of text box "rightBox" of page 2 of front document to "Trade Gothic LT Std Light"
				set size of story 1 of text box "rightBox" of page 2 of front document to 7
				set color of story 1 of text box "rightBox" of page 2 of front document to "Magenta"
				set justification of every paragraph of text box "rightBox" of page 2 of front document to right justified
			else if result = {button returned:"Salir"} then
				if theMessage is "" then
					set the clipboard to ""
					return
				else
					set the clipboard to "Spreads con cajas para folio duplicadas: " & return & theMessage
					return
				end if
				return
			end if
		end if
		
		if leftDup > 1 and rightDup > 1 then -- if there are left and right duplicated folio boxes
			tell document theProject
				set view scale to fit spread in window
			end tell
			copy name of front project to the end of the revList -- Add current document name to the revision list
			with timeout of 500000 seconds
				display dialog "En el archivo \"" & theProject & "\" existen : " & leftDup & " folios izquierdos y " & rightDup & " folios derechos." buttons {"Continuar"} default button 1 with icon 2 with title vers giving up after 30
			end timeout
		else if leftDup > 1 and rightDup = 1 then
			tell document theProject
				set view scale to fit spread in window
			end tell
			copy name of front project to the end of the revList -- Add current document name to the revision list
			with timeout of 500000 seconds
				display dialog "En el archivo \"" & theProject & "\" existen : " & leftDup & " folios izquierdos." buttons {"Continuar"} default button 1 with icon 2 with title vers giving up after 30
			end timeout
		else if leftDup = 1 and rightDup > 1 then
			tell document theProject
				set view scale to fit spread in window
			end tell
			copy name of front project to the end of the revList -- Add current document name to the revision list
			with timeout of 500000 seconds
				display dialog "En el archivo \"" & theProject & "\" existen : " & rightDup & " folios derechos." buttons {"Continuar"} default button 1 with icon 2 with title vers giving up after 30
			end timeout
		end if
	end repeat
end tell
-- disabled for testing **************
(*
try
	set {TID, text item delimiters} to {text item delimiters, return}
	set theMessage to revList as text
	set text item delimiters to TID
end try
tell application "QuarkXPress"
	if theMessage is "" then
		beep
		set the clipboard to ""
		with timeout of 500000 seconds
			display dialog "¡Listo!. Por favor revisar y guardar los archivos." with icon 1 buttons {"OK"} default button "OK" with title vers
		end timeout
	else
		beep
		with timeout of 500000 seconds
			display dialog "¡Listo!. Por favor revisar y guardar los archivos." & return & return & "Recordar que estos spreads tienen folios duplicados :" & return & theMessage with icon 1 buttons {"Crear Post-it", "Copiar", "OK"} default button "OK" with title vers
		end timeout
		if result = {button returned:"Copiar"} then
			set the clipboard to vers & return & "Spreads con cajas para folio duplicadas: " & return & theMessage
		else if result = {button returned:"Crear Post-it"} then
			set timeStamp to current date
			set the clipboard to vers & return & timeStamp & return & "Spreads con cajas para folio duplicadas: " & return & theMessage
			tell application "System Events"
				set frontProcess to first application process whose frontmost is true
				set ImAScript to (frontProcess's name is "System Events")
				keystroke tab using command down
				repeat while (frontProcess's frontmost)
					delay 0.2
				end repeat
				if (ImAScript) then
					-- display dialog " - 6 - " giving up after 1 buttons ""
					set frontProcess to first application process whose frontmost is true
					tell frontProcess
						-- display dialog " - 7 - " giving up after 1 buttons ""
					end tell
					keystroke tab using command down
					-- display dialog " - 8 - " giving up after 1 buttons ""
					repeat while (frontProcess's frontmost)
						delay 0.2
					end repeat
				end if
			end tell
			-- display dialog " - 9 - " giving up after 1 buttons ""
			tell application "Stickies" to run
			-- display dialog " - 10 - " giving up after 1 buttons ""
			tell application "System Events"
				-- display dialog " - 11 - " giving up after 1 buttons ""
				set frontmost of application process "Stickies" to true
				tell Stickies
					-- display dialog " - 12 - " giving up after 1 buttons ""
				end tell
				keystroke "nv" using command down
			end tell
		else
			set the clipboard to ""
		end if
	end if
end tell
*)

Browser: Safari 537.36
Operating System: Mac OS X (10.9)

I narrowed down the problem and found the culprit (well I’m the culprit because I wrote the buggy code).

This inoffensive statement is causing the problem:


tell application "QuarkXPress"
	activate
				tell layer "Default" of page 1 of front document
					-- {top position, left position, bottom position, right position} o  también {Y,X,Y+H,X+W}
					make new text box at beginning with properties {bounds:{"223 mm", "7 mm", "227 mm", "17 mm"}, name:"leftBox", runaround:none runaround}
				end tell
end tell

Any idea how this would be disabling undo command in QuarkXpress 10?
Thanks!