I’m trying to improve upon a few scripts I’ve written for automating software installations. Currently I have set delays to allow for the installation and used keystrokes to navigate through the menus. Some applications don’t allow for keyboard navigation so am using an application called UI Browser to give me the menu and button names so the script can click the necessary.
I’m trying to faze out using timed delays and replace them with an if statement that will look for a certain static text field in the window that follows the installation. I am testing this method on Flip4Mac as it’s a small install.
This is the if statement I’ve come up with but it doesn’t do as I’m wanting! Any help would be greatly appreciated. The whole script is listed below also if anyone needs it.
tell application "System Events"
tell process "Installer"
repeat
if static text of window "Install Flip4Mac WMV" is "The installation was successful." then
click button "Close" of window "Install Flip4Mac WMV"
end if
end repeat
end tell
end tell
This is the entire script as it stands.
tell application "Finder"
do shell script "open '/Volumes/Macintosh HD/Users/TS/Desktop/Flip4Mac WMV.mpkg'"
tell application "System Events"
tell process "Installer"
delay 0.5
click button "Continue" of window 1
delay 0.5
click button "Continue" of window "Install Flip4Mac WMV"
delay 0.5
click button "Continue" of window "Install Flip4Mac WMV"
delay 0.5
click button "Continue" of window "Install Flip4Mac WMV"
delay 0.5
click button "Agree" of sheet 1 of window "Install Flip4Mac WMV"
delay 0.5
click button "Install" of window "Install Flip4Mac WMV"
delay 3
keystroke (ASCII character of 13)
# if statement goes here
end tell
end tell
end tell
tell application "System Events"
tell process "Installer"
repeat while static text of window "Install Flip4Mac WMV" is not "The installation was successful."
// nothing needed here
end repeat
click button "Close" of window "Install Flip4Mac WMV"
end tell
end tell
this is a version with controlled delays. It considers also the password entry
I tested it until the moment after entering the password and pressing the OK button.
So I hope it will wait properly for the last window and presses the Close Button
property myAdminPassword : "¢¢¢¢¢¢¢¢"
property flip4MacMainWindowName : "Install Flip4Mac WMV"
set Flip4MacPath to POSIX path of (path to desktop) & "Flip4Mac WMV.mpkg"
do shell script "open " & quoted form of Flip4MacPath
tell application "System Events"
tell process "Installer"
repeat until exists window 1
delay 0.1
end repeat
click button "Continue" of window 1
repeat until exists window flip4MacMainWindowName
delay 0.1
end repeat
tell window flip4MacMainWindowName
click button "Continue"
my waitForTextAndClickButton("Important", "Continue")
my waitForTextAndClickButton("Software License", "Continue")
repeat until exists sheet 1
delay 0.1
end repeat
click button "Agree" of sheet 1
my waitForTextAndClickButton("Standard Install", "Install")
end tell
end tell
tell process "SecurityAgent"
repeat until exists window 1
delay 0.1
end repeat
tell window 1
set value of text field 2 of scroll area 1 of group 1 to myAdminPassword
click button "OK" of group 2
end tell
end tell
my waitForTextAndClickButton("The installation was successful", "Close")
end tell
on waitForTextAndClickButton(theText, theButton)
tell application "System Events"
tell process "Installer"
tell window flip4MacMainWindowName
repeat until value of static text 1 begins with theText
delay 0.1
end repeat
click button theButton
end tell
end tell
end tell
end waitForTextAndClickButton
If you’re using a simple mpkg like flip4mac you can simply run the shell script installer and don’t need gui scripting at all. Use do shell script with administrator privileges because installer want a admin account to install the packages.
I was using Flip4Mac as a trial as it is a small install that only takes a few seconds. I am scripting other applications too with customisable options such Logic Studio and Final Cut.
I tried the two examples above and they both loop but neither actually finish the install by clicking the close button. Is there something missing from within the script that needs to be changed?
I noticed the last script was set to button 1 for close which is actually button 3 but it still didn’t work sadly.