on Idle handler doesn't work properly...for me!

Hi everybody! :slight_smile:

I’m new on AppleScript and I have issues with my script:
I want that my script make an automator file to run and then wait some seconds before it run again. I want to see how much time remains before the script run again and I even want to stop the countdown at any time (for this i use Idle Handler). This is my script:


property runn : false
property x : 2200
property y : 0

on DoTheForm()
	-- code to do 
	set string value of text field "Tempo" of window "Window" to y
	set x to y
	
	tell application "Safari"
		activate
	end tell	
	
	tell front window of application "Safari" to set current tab to tab "Restaurant City su Facebook"
		
	do shell script "automator /Users/andrea/Documents/Restourant.workflow"
end DoTheForm


on idle
	-- here we check whether we're in Run state or not
	-- by checking the runn variable
	-- if runn is true it starts with DoTheForm and then set runn to false
	-- if runn is false it displays a countdown with a constantly refresh of text field in the Window
	
        if runn = true then
		DoTheForm()
		set runn to false
	end if

	set string value of text field "Tempo" of window "Window" to x
	set x to (x - 1)
	
	if x = 0 then
		set runn to true
	end if
	
	return 1
end idle



on clicked theObject
	
	if name of theObject = "Via" then
		
		set y to (get string value of text field "Tempo" of window "Window")
		
		if runn is false then
			set name of theObject to "Stop" -- rename the button
			set runn to true -- here's our global variable
			idle
			-- call the idle handler
		else -- we're already running
			set runn to false -- this will stop the next idle handler from filling out the form
			set content of theObject to "Via"
		end if
	else if name of theObject = "Esci" then
		quit -- exit program
	end if
end clicked

My problem is that “on Idle handler” doesn’t work properly: It doesn’t refresh text field of Window and doesn’t restart each second as on Idle handler have to do…if I understand “on Idle” tutorial…

Someone can help me with my script? Thank you so much!!!
Bye :smiley:

P.S. Sorry for my terrible english!

EDIT: I’ve tried more and more and I found the problem: Idle handler doesn’t restart…never, instead the rest of the script work properly. I put “return” even in clicked handler but it doesn’t work. Any help???
Thank you so much! :smiley:

I solved the problem :smiley: : I forgot to check the “idle” switch in Interface Builder.

For who has my problem:
Open MainMenu.nib project file in Interface Builder, click the “File’s Owner” icon, and then in the AppleScript info pane, check Application → idle, applied to your main script.
Now all will go right!

Hi everybody! :smiley: