syntax to keep script-app from timing out

I can’t seem to find this when I search, but I’m sure its a gimme.

I have a script that I want to run while another app (QXP) is running.

I have saved it as an application and checked the “Stay Open” checkbox, but it consistently times out.

property Idle_interval : 1
property WarnMe : false
on idle
	tell application "System Events"
		if exists application process "QuarkXPress" then
			if WarnMe then
				tell application "QuarkXPress"
					beep
					if exists document 1 then
						if modified of document 1 is true then
							set decision to the button returned of (display dialog "Shouldn't you save now?" buttons ¬
								{"Yeah, do it", "Nah"} default button 2 giving up after 15 with icon note)
							if decision = "Yeah, do it" then
								tell document 1 of application "QuarkXPress"
									save
								end tell
							end if
						end if
					end if
				end tell
			end if
			set Idle_interval to 7 * minutes
			set WarnMe to true
		else
			--tell me to display dialog "Quark is not running now..." default button 2 giving up after 5 with icon note
			set Idle_interval to 1 * minutes
			set WarnMe to false
		end if
	end tell
	return Idle_interval -- in seconds
end idle

Here’s one suggestion I can make. Your tell application “QuarkXPress” statement is inside of a tell application “System Events” statement. So essentially your are telling system events to tell quarkxpress something. I would remove the quark stuff from inside of the system events tell block.

Something like this would be better and may even fix your problem.

set quarkIsRunning to false
tell application “System Events”
if exists application process “QuarkXPress” then set quarkIsRunning to true
end

if quarkIsRunning and WarnMe then
tell application “QuarkXPress”
– do quark stuff here
end
end

Here’s another thing I see. This statement…

tell document 1 of application “QuarkXPress”

Since you are already inside of a tell application “QuarkXPress” statement you probably should just use… tell document 1