If statement failing

one of the end ifs wants to be an end repeat even though. im not ready for it to be ended. and i want the timer to only ask you if you want to activate if yoiu said yes earlier. basicly i want it to work…


tell application "iTunes"
	activate
	set timer_maybe to button returned of (display dialog "would you like to set a timer to shutdown?" buttons {"yes", "no"} default button 1)
	if timer_maybe = "yes" then set how_long to text returned of (display dialog "How Long?" default answer "In minutes") as number
	if timer_maybe = "no" then
	repeat
		set button_push to button returned of (display dialog "         controls         " buttons {"track change", "PlayPause", "quit"} default button 2)
		if button_push = "track change" then
			set track_button to button returned of (display dialog "next track or last track?" buttons {"last track", "next track"})
			if track_button = "next track" then next track
			if track_button = "last track" then back track
			end if
		if button_push = "PlayPause" then playpause
		if button_push = "quit" then exit repeat
		end if
		set start_timer to button returned of (display dialog "if you set a timer would you like to start it?" buttons {"yes", "no"} default button 1)
			if start_timer = "yes" then
			delay (""& how_long &"" * minutes)
			tell app "finder"
			shut down
			end tell
			if start_timer = "no" then
			end if 
	end repeat
	quit application "iTunes"
end tell
tell application "Finder"
	set shutdown_button to button returned of (display dialog "would you like to shut down?" buttons {"Yes", "No"})
	if shutdown_button = "yes" then shut down
	if shutdown_button = "no" then
	end if
end tell

I’m really not clear about what it is you are trying to achieve. What is clear is that you need more work on your compound if-then-else statements. Is this what you mean?

set timer_maybe to button returned of (display dialog "would you like to set a timer to shutdown?" buttons {"yes", "no"} default button 1)
if timer_maybe = "yes" then
	set how_long to text returned of (display dialog "How Long? (In minutes)" default answer "") as number
	delay (how_long * minutes)
	tell application "Finder" to shut down
else if timer_maybe = "no" then
	tell application "iTunes"
		activate
		repeat
			set button_push to button returned of (display dialog "          ?controls          ?" buttons {"track change", "PlayPause", "quit"} default button 2)
			if button_push = "track change" then
				set track_button to button returned of (display dialog "next track or last track?" buttons {"last track", "next track"})
				if track_button = "next track" then
					next track
				else if track_button = "last track" then
					back track
				end if
			else if button_push = "PlayPause" then
				playpause
			else if button_push = "quit" then
				exit repeat
			end if
		end repeat
		quit
	end tell
	set shutdown_button to button returned of (display dialog "Would you like to shut down?" buttons {"Yes", "No"})
	if shutdown_button = "Yes" then tell application "Finder" to shut down
end if

Jon

Yeah, what Jonn said. Basically, pay attention to your if statements that have more than one condition. In other words if there are two possible inputs or arguments to an if statement it should go like this:


If variable_A = X then
     do something
else if variable_A = Y then
     do something different
end if

In your code, you didn’t include any instances of “else if” where they need to be. You just made additional if statements. Just remember, if there’s one or more “if’s” between the opening “if” and the “end if”, then you need to precede each additional “if” with the word “else”. Clear on that?
Fix your “if-then-else” statements, and your script should work.
Good Luck.