I work with a not-for-profit charity called Ride for Life (www.rideforlife.com) and we need a simple script that will click on a button on a web page every 3 minutes.
Let me give you a little background so you can see how this will help us.
Our organization helps people with ALS - Lou Gehrig’s disease. Every spring we hold our annual fundraising event called the Ride for Life where patients ride their electric wheelchairs great distances to help raise awareness for the disease - in this case they’re traveling 150 miles from Manhattan to Montauk on the tip of Long Island. The trip will take 10 days. We have a GPS unit with us which allows people on our website to track our progress. We have come up with a way to serve the GPS map image on our site. We currently use a script which refreshes the browser page - that keeps us logged into the GPS service. However, sometimes we get logged off. Since we make the Safari home page the log in page (the one above) and Safari automatically pops in the name and password, we need a script that will click on the LOGIN button. It sounds a little crazy but it works well. The problem is that this year the login page is different and simply hitting RETURN via the old script won’t activate the button.
Since we don’t run into the problem of having to log in after being dropped very often… Is there a way for the script to check if the button is actually on the screen before executing? If we’re still logged in we don’t need the script to run.
tell application "System Events" to tell button "Login" of group 25 of UI element 1 of ¬
scroll area 1 of group 2 of window 1 of process "Safari" to if exists then click
Thanks so much for the script… but I’m unsure how to run it. I opened it in the editor and saved it as an application, like my other scripts. When I tried to run it it opens then seems to close. It doesn’t stay active like my other scripts and it doesn’t seem to click the button. What am I doing wrong?
Your best bet is to post one of your other scripts here (use the Applescript button at the top of the message box and paste the script between the brackets shown below. Then Kai or someone else can slip his new trigger line right into it for you.[code]
[/code]
If you can’t do that, then wait a bit and someone (maybe me) will write you an on idle script that’ll do it. Does the original script do anything else besides log in as necessary? Do you lose the whole page?
In the meantime, something like this is what you want:
on run
activate application "Safari"
end run
on idle
tell application "System Events"
tell button "Login" of group 25 of UI element 1 of ¬
scroll area 1 of group 2 of window 1 of process "Safari" to if exists then click
if exists process "Safari" then
return 180 -- these are seconds
else
quit
end if
end tell
end idle
on quit
-- you can do other stuff before quitting here
continue quit
end quit
You save this from your script editor as a stay open application. Double-click it to start it. Quit Safari to stop it (or go to the Activity Monitor application and kill it there - you’ll see it by name.)
On Adam’s suggestion… here is the script we use to keep connected to the GPS server. If somehow the click login button script Kai wrote can be incorporated, that would be great.
Thanks!
on idle
tell application "Safari"
do JavaScript "window.location.reload( true )" in document 1
tell me to delay 10 -- seconds
activate
tell application "System Events" to keystroke (ASCII character 13)
return (3 * 60) -- (minutes * seconds) between refresh
end tell
end idle
on idle
tell application "Safari" to do JavaScript "window.location.reload( true )" in document 1
delay 10 -- seconds
activate application "Safari"
tell application "System Events" to tell button "Login" of group 25 of UI element 1 of ¬
scroll area 1 of group 2 of window 1 of process "Safari" to if exists then click
3 * minutes
end idle
on idle
tell application "Safari"
do JavaScript "window.location.reload( true )" in document 1
delay 10 -- seconds
activate
tell application "System Events" to tell button "Login" of group 25 of UI element 1 of ¬
scroll area 1 of group 2 of window 1 of process "Safari" to if exists then click
return (170)
end tell
end idle
What this is doing is this: the do JavaScript line simply refreshes the page every time aroung (3 minutes).
“activate” does just that - either starts Safari or brings it to the front.
The tell application System Events … (Kai’s line) only functions if the window is a login window - otherwise is doesn’t.
return 170 is 10 seconds short of three minutes, but you’ve already paused for 10 so the cycle will take 180.
PLEASE test this before it is vital that it work.
EDIT - Oops - I didn’t realize Kai was on line. Glad to see I was suggesting the same thing, though.