trouble with repeat loop inside a complicated if statement

I am trying to create an applescript that is launched (via crontab) at 6am to be used as an alarm clock. however I am running into some trouble with a repeat block. I have the script opening up iTunes and playing the alarm playlist, while displaying a dialog. I would like to have the dialog displayed until the Button "OK’ is returned. Meanwhile, iTunes is playing and the dialog still stays visible, i would like to have the computer talk to me and say “Time to wake up!” every 20 sec. It seems when i try to execute the script, it skips over my repeat loop. I have tried different ways to accomplish this, but I am stuck. Any suggestions?


-- WEEKDAY

set theDate to current date
set theDay to weekday of theDate as string

set theWeekday to theDay = "Monday" or theDay = "Tuesday" or theDay = "Wednesday" or theDay = "Thursday" or theDay = "Friday"

if theWeekday then
	tell application "iTunes"
		play playlist "Alarm"
	end tell
	delay 10
	
	set timeToWakeUp to display dialog "Time to wake up!" buttons {"Snooze", "OK"} default button "OK"
	set answer to button returned of timeToWakeUp
	
	repeat until answer is "OK"
		tell application "iTunes" to set sound volume to minVol
		delay 0.5
		say "Time to wake up sir!"
		delay 0.5
		tell application "iTunes" to set sound volume to maxVol
		delay 30
	end repeat
	
	if answer is "OK" then
		tell application "iTunes"
			quit
		end tell
	end if
end if

Model: 2007 Macbook Pro
AppleScript: 2.3
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Hi,

display dialog can’t continue to execute further code while displaying the dialog.
Fur this purpose there is a parameter giving up to dismiss the dialog after a certain amount of seconds

Try this


-- WEEKDAY

set theDay to weekday of (current date) as integer -- Sunday = 1 - Saturday = 7
set theWeekday to theDay > 1 and theDay < 7

if theWeekday then
	tell application "iTunes" to play playlist "Alarm"
	delay 10
	repeat
		set {button returned:buttonReturned, gave up:gaveUp} to display dialog "Time to wake up!" buttons {"Snooze", "OK"} default button "OK" giving up after 20
		if gaveUp then
			tell application "iTunes" to set currentVol to sound volume
			tell application "iTunes" to set sound volume to 20
			delay 0.5
			say "Time to wake up sir!"
			delay 0.5
			tell application "iTunes" to set sound volume to currentVol
		else if buttonReturned is "Snooze" then
			delay 10
		else if buttonReturned is "OK" then
			exit repeat
		end if
	end repeat
	quit application "iTunes"
end if