So far what I've got is giving me the following:
On first run of the repeat Time1 correctly enters 07:30 and Time2 correctly enters 08:00
On second run of the repeat Time1 correctly enters 08:00 and Time2 correctly enters 08:30
On third run and any subsequent run Time1 is always 08:30 and Time2 is always 08:30.
What am I doing that is not keeping the loop running of adding 30 minutes after the second time through?
Here is the code I've got so far:
on time_in_hhmm(s)
(*
integer s : seconds from 00:00:00
return string : time in hh:mm notation
*)
set t to current date
set t's time to s
(t as «class isot» as string)'s text 12 thru 16
end time_in_hhmm
on time_in_hhmm2(t)
(*
integer t : seconds from 00:00:00
return string : time in hh:mm notation
*)
set t2 to current date
set t2's time to (t + (30 * minutes))
(t2 as «class isot» as string)'s text 12 thru 16
end time_in_hhmm2
on setValueOfElementByName_index_value(n, i, v)
(*
string n : DOM element name
integer i : index of the target element in collection
string v : value to which the target element's value is set
*)
set jstime to "document.getElementsByName('" & n & "')[" & i & "].value = '" & v & "';"
tell application "Safari" to do JavaScriptjstimeinwindow 1's current tab
end setValueOfElementByName_index_value
to inputByName(theName, num, theValue)
tell application "Safari"
do JavaScript "document.getElementsByName('" & theName & "')[" & num & "].value='" & theValue & "';" in document 1
end tell
end inputByName
to clickName(theName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByName('" & theName & "')[" & elementnum & "].click();" in document 1
end tell
end clickName
set dialog to display dialog "How many cases do you want to enter?" default answer ""
set cases to text returned of the result
set originalcase to cases
set s to choose from list {"07:30", "08:00", "08:30"}
if s = false then error number -128 -- user cancel
set s to s's item 1
set {h, m} to {0 + (s's text 1 thru 2), 0 + (s's text 4 thru 5)}
set t to time_in_hhmm(h * hours + (m + 30) * minutes)
--return {s, t}
setValueOfElementByName_index_value("Time1", 0, s)
setValueOfElementByName_index_value("Time2", 0, t)
repeat until cases = 0
if cases < originalcase then
setValueOfElementByName_index_value("Time1", 0, t)
set t2 to time_in_hhmm2(h * hours + (m + 30) * minutes)
setValueOfElementByName_index_value("Time2", 0, t2)
set t to t2
end if
set js to "
var ee = document.evaluate(
'//a[contains(., \"Save this case, then start a NEW case on the SAME DAY\")]',
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);
var e = ee.singleNodeValue;
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
e.dispatchEvent(evt);
"
tell application "Safari"
activate
do JavaScriptjsinwindow 1's current tab
end tell
set cases to cases - 1
end repeat