so, i wrote a script that will automatically log into a website. but, first, it checks if they are using Google Chrome…if so, then it will open chrome, take you to the page, then log in. If the user doesn’t have chrome installed, it will open safari and do the same. now, the weird part is that when the script is run, it automatically opens safari. doesn’t do anything with it (assuming that chrome is installed), but it opens it. any suggestions as to what i might be doing wrong here?
set doesExist to false
try
do shell script "osascript -e 'exists application \"Google Chrome\"'"
set doesExist to true
end try
delay 1
if doesExist is true then
tell application "Google Chrome"
open location "https://www.somepage.com"
tell active tab of window 1
repeat while loading is true
delay 0.1
end repeat
execute javascript "document.forms['Form1']['UsernameTextbox'].value = 'Username'"
execute javascript "document.forms['Form1']['PasswordTextbox'].value = 'Password'"
execute javascript "document.forms['Form1']['LoginButton'].click()"
end tell
end tell
else
tell application "Safari"
tell (make new document) to set URL to "https://www.somepage.com"
activate
delay 1
repeat
local pageState
set pageState to do JavaScript "document.readyState" in document 1
if pageState = "Complete" then exit repeat
delay 0.2
end repeat
delay 1
set doc to document "Login"
do JavaScript "document.forms['Form1']['UsernameTextbox'].value = 'Username'" in doc
do JavaScript "document.forms['Form1']['PasswordTextbox'].value = 'Password'" in doc
tell application "System Events"
keystroke return
end tell
end tell
end if