Fading window in/out

Ok so I’m having my window fade in and out using this subroutine

on fadeWindow(theWindow, theDirection)
	tell theWindow
		if theDirection = "out" then
			set opaque to false
			repeat with i from 10 to 0 by -1
				set alpha value to (i / 10)
				do shell script "sleep 0.01"
		         end repeat
			
		else if theDirection = "in" then
			repeat with i from 0 to 10
				set alpha value to (i / 10)
				do shell script "sleep 0.01"
			end repeat
			set opaque to true
		end if
	end tell
end fadeWindow

and then calling it in handlers like this

on should close theObject
	if the name of theObject is "main" then
		fadeWindow(window "main", "out")
	end if
end should close

on opened theObject
	if the name of theObject is "main" then
		fadeWindow(window "main", "in")
	end if
end opened

There are a couple problems however. When it opens on launch the window fades in but jumps a little right at the end. And when I close the window using the red x button it fades out fine but then you cannot get the window to open again :frowning:
Anyone have ideas why? Thanks so much!

  • Hendo

Ah perfect, thanks a bunch Jaques :slight_smile: