Intermittent issue with script not closing install

Hi all,

The attached script installed Flip4Mac onto the users computer. We thought we had this sussed but for some reason it is intermittently not closing. Can anyone see any obvious faults or ways to improve it? We’ve added a few if statements that deal with installing on a 10.5 and 10.6 machine.

Thanks in advance.

Will

property Flip4MacWindow : "Install Flip4Mac WMV"

set Flip4MacPath to POSIX path of (path to desktop) & "Flip4Mac/installer/Flip4Mac WMV.mpkg" -- Opens the installer on the user's desktop

tell application "Finder"
	
	do shell script "open " & quoted form of Flip4MacPath
	
	tell application "System Events"
		tell process "Installer"
			delay 2
			
			-- Initial popup window (This package will run a program to determine if the software can be installed.)
			click button "Continue" of window 1
			delay 0.5
			
			-- Welcome window
			my waitForTextAndClickButton("Welcome to", "Continue")
			delay 0.5
			
			-- Important Information window
			my waitForTextAndClickButton("Important Information", "Continue")
			delay 0.5
			
			-- Software License window
			my waitForTextAndClickButton("Software License Agreement", "Continue")
			delay 0.5
			
			click button "Agree" of sheet 1 of window Flip4MacWindow
			delay 0.5
			
			-- Install destination window that appears sometimes (usually after an initial system boot)
			if value of static text 1 of window Flip4MacWindow is equal to "Select a Destination" then
				delay 0.5
				click button "Continue"
			else if value of static text 1 of window Flip4MacWindow is equal to "Standard Install on "Macintosh HD"" then
				
				-- License Agreement drop down
				my waitForTextAndClickButton("Standard Install", "Install")
			end if
			delay 2
			
			keystroke (ASCII character of 13) -- Return keystroke on the password field
			
			tell window "Install Flip4Mac WMV"
				-- Waiting for install process to complete and which of the 2 windows will appear as to what to continue with to finish
				repeat until value of static text 1 is equal to "The installation was completed successfully." or value of static text 1 is equal to "Installation completed successfully" or value of static text 1 is equal to "Flip4Mac WMV Upgrade"
					delay 0.1
				end repeat
				
				-- This handles a 10.6 installation
				if value of static text 1 is equal to "The installation was completed successfully." then
					delay 2
					my waitForTextAndClickButton("The installation was", "Close")
					-- This handles a 10.5 installation
				else if value of static text 1 is equal to "Installation completed successfully" then
					delay 2
					my waitForTextAndClickButton("Installation completed", "Close")
				else if value of static text 1 is equal to "Flip4Mac WMV Upgrade" then
					delay 2
					my waitForTextAndClickButton("Flip4Mac", "Continue")
					delay 2
					-- This handles a 10.6 installation
					if value of static text 1 is equal to "The installation was completed successfully." then
						delay 2
						my waitForTextAndClickButton("The installation was", "Close")
						-- This handles a 10.5 installation
					else if value of static text 1 is equal to "Installation completed successfully" then
						delay 2
						my waitForTextAndClickButton("Installation completed", "Close")
						delay 2
					end if
				end if
				
				tell current application
					say "Flip 4 Mac installation completed successfully" using "Trinoids"
				end tell
				
			end tell
		end tell
	end tell
end tell

-- This is the function
on waitForTextAndClickButton(theText, theButton)
	tell application "System Events"
		tell process "Installer"
			tell window Flip4MacWindow
				repeat until value of static text 1 begins with theText
					delay 0.1
				end repeat
				delay 2
				click button theButton
			end tell
		end tell
	end tell
end waitForTextAndClickButton

I can’t see any overt errors to pinpoint your problem however I see where you can make improvements that might fix your problem.

  1. when testing out a script always use large delays. Then once you know the code is correct then you can make the delays smaller to speed up the script. If you run into problems after making them smaller then you’ll know it’s the length of the delays that’s causing the problem. An easy way to do this is to make a variable at the top of the script and use the variable throughout the script. Then you only need to adjust that one variable and you know all of your delays are getting adjusted. Something like this…
set myDelay to 1

delay myDelay
delay (myDelay * 3) -- if you need a longer delay
delay (myDelay / 2) -- if you need a shorter delay
  1. you have all of your code inside of a Finder tell block. In essence you are telling the Finder to perform all of your tasks. Why are you telling the Finder to “do shell script” or “tell application “System Events”” or any of the other stuff? The Finder is not needed for any of that. In addition you are telling system events to “tell current application” something. Why? All of these nested tell blocks of code could cause your problem. Un-nest them. Have each tell block separate from the others. You can get rid of the Finder tell totally. It doesn’t seem the Finder is needed for any of your commands. Also applescript can perform your “say” command, so why are you telling any application to perform the say command? In general only tell an application to do something if it’s needed. Your code will run faster and have less conflicts.

Thank you for the reply, that’s really helpful. What you’ve said makes sense. I’ll amend the script and see how it performs afterwards.

Shall report back!