My .scpt script fail sometimes

We created a script .scpt that is run before an operation. the script use a login via Safari. almost always it works but sometimes not. if we log on the machine the script will work. do you have idea of the problems? Thanks

Answered by DTS Engineer in 821288022

without any additional information to go on, I could guess that perhaps Safari has not finished loading the page for the login?

without any additional information to go on, I could guess that perhaps Safari has not finished loading the page for the login?

If you can provide some additional information, perhaps I can tell you more.

We execute the script via SSH with osascript "name of script.scpt"

Consider that the script it works.

This is the script .scpt that we call:

set usr to (do shell script "echo $USR")

set pwd to (do shell script "echo $PWWD")

set maxRetries to 3

set attempt to 0

set loginSuccess to false

set statusFile to "/Users/digicertusr/Downloads/success.txt"

repeat while (attempt < maxRetries and loginSuccess is false) set attempt to attempt + 1 tell application "Safari" activate open location "https://xxxxxx.com" end tell

delay 5
tell application "System Events"
	keystroke usr
	delay 5
	keystroke tab
	delay 3
	keystroke pwd
	delay 5
	keystroke return
end tell

tell application "Safari"
	activate
	open location "https://www.wikipedia.org"
end tell

delay 5

tell application "Safari"
	set pageTitle to name of front document
end tell

if pageTitle contains "Wikipedia" or pageTitle contains "Sign On" or pageTitle contains "xxxxxxxxxx" then
	set loginSuccess to true
else
	set loginSuccess to false
end if

tell application "Safari"
	close front window
	quit
end tell

end repeat

if loginSuccess is false then do shell script "echo 'FAILED' >> /Users/digicertusr/Downloads/failed.log" end if

Thanks

My .scpt script fail sometimes
 
 
Q