Applescript login into website not quick enough.
Hi,
I am hoping that someone might be able to help me. I have a script to login to the YMCA to reserve a place in a class. The script works for 90% of all events except for the very popular ones - for example for certain classes (the popular ones) all 45 slots are taken within 2-3 seconds of the login window timeframe opening. You can sign into a class up to 36hours ahead of time.
I believe that my script is not fast enough. I have timers in the log file but I can’t record sub-second times - so I only know that I fail within the zero or one second after the hour.
If you would be so kind as to look at my script and see if there is a better way to do the signin that might be quicker.
Many thanks,
Terry
After the script I include the crontab data and the bash file.
Here’s the script:
the first part is missing as I exceeded the 5000 character limit.
set timestamp3 to (current date)
tell application "System Events"
tell process "Safari"
open location URL1 & URL2 & "-" & URL3 & URL4 & URL5 & URL6 & URL7 & URL8
delay 5
-- display dialog "the scpt script is still running."
end tell
-- tell application "System Events"
tell application "Safari"
activate
delay 5
if user is equal to "bf" then
do JavaScript "document.forms[0].login.value='fname_lastname@comcast.net'" in document 1
delay 2
do JavaScript "document.forms[0].password.value=‘badpswd’” in document 1
end if
if user is equal to "tf" then
do JavaScript "document.forms[0].login.value='fname_lastname1@comcast.net'" in document 1
delay 2
do JavaScript "document.forms[0].password.value=‘badpswd’” in document 1
end if
-- display dialog "Passed the if" & user -- (for debugging)
--
-- delay until the exact minute
--
repeat
set myDate to date string of (current date)
set myTime to time string of (current date)
set myMin to minutes of (current date)
if myMin is equal to 0 then
exit repeat
end if
if myMin is equal to 15 then -- I change this for testing.
exit repeat
end if
end repeat
set timestamp4 to (current date)
-- display dialog "the exit minute is " & myMin
-- delay 0.02 -- this is for testing with repeat section commented out
--
-- and then press the login button
--
do JavaScript "document.forms[0]['submit'].click()" in front document
delay 0.3
--
-- now click the reserve spot
--
do JavaScript "document.forms[0]['submit'].click()" in front document
set timestamp5 to (current date)
delay 2
set someText to "Y_sched.scpt has hopefully Reserved the Spot. "
do shell script "echo " & quoted form of someText & timestamp5 & " " & fnam & " " & user & " " & classnbr & " >> " & quoted form of logFile
tell application "System Events"
click at {250, 235}
end tell
--
-- now logout of session
--
delay 2
open location logoutURL
delay 2
--
-- now kill window
--
close document "GroupExPRO.com"
end tell
This is a portion of the crontab data
# The following statement points to a bash script that will invoke the AppleScript and pass the variables (Var1,2,3)
CRON_WRAPPER=/Users/ymca/tasks/Y_sched/Y_sched.sh
# 0900 on Sun for Tues classname - instructor
59 20 * * 0 $CRON_WRAPPER &> /Users/ymca/tasks/Y_sched/logs/Y_sched_$(date +\%a).log 0Sun4Tue_9A~bf~12345678
contents of Y_sched.sh:
#!/bin/bash
#
# This script is normally invoked by crontab ($CRON_WRAPPER)
#
# osascript /Users/ymca/tasks/Y_sched/Y_sched.scpt -ss - $1 $2 $3 $4 # this doesn't work
#
# Example of variables passed:- "0sun4tue_9A~tf~12345678” The ~ is to be used as a text field seperator
#
osascript /Users/ymca/tasks/Y_sched/Y_sched.scpt $1 $2 $3 $4
# osascript /Users/ymca/tasks/Y_sched/Y_sched.scpt "0sun4tue_9A~tf~11885688" #testing Manual