Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2012, 11:59 AM   #1
chmedly
macrumors newbie
 
Join Date: Sep 2006
Script to cause a delayed click on webpage link?

I have a computer setup for remote control that is connected to the internet via a Clear Atlas wimax internet modem. I'm looking for a way to reset this modem remotely. There is a disconnect/connect button in it's local control webpage that when clicked disconnects the modem from the internet. I've found that when in front of this computer I can wait a few seconds and click connect again and it does what what I need it to do as far resetting. I'd like to write a script so that I can do this disconnect then reconnect routine while remotely controlling it. Basically, I need a way to cause another mouse click on the same button after some set amount of time. I started to play around with automator but had some problems. I'm looking for help and ideas about how to make this work.
chmedly is offline   0 Reply With Quote
Old Dec 16, 2012, 01:00 PM   #2
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
So interacting with a link/button on a page is probably a task best suited to Javascript.

Do you ever visit this page and NOT do what you are trying to do? If not, then you could pretty easily make a Safari Extension that checks the URL of the page, and if it matches certain criteria it executes the JS to do what you are trying to do.

Then simply make shell or applescript to open safari, visit that url, and close the safari window.
jared_kipe is offline   0 Reply With Quote
Old Dec 16, 2012, 04:14 PM   #3
ytk
macrumors regular
 
Join Date: Jul 2010
Probably the easiest way is to just use a macro program. I like Keyboard Maestro for general purpose macros, but BetterTouchTool will work as well and it's free.

In BTT, you can define a shortcut (keyboard or mouse) to perform a series of actions. First define your shortcut to perform a left click, then attach two additional actions: a delay, followed by another left click.

It's a bit of a kludge, but it's decidedly easier than mucking about with Javascript.
ytk is offline   0 Reply With Quote
Old Dec 17, 2012, 11:21 AM   #4
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by ytk View Post
Probably the easiest way is to just use a macro program. I like Keyboard Maestro for general purpose macros, but BetterTouchTool will work as well and it's free.

In BTT, you can define a shortcut (keyboard or mouse) to perform a series of actions. First define your shortcut to perform a left click, then attach two additional actions: a delay, followed by another left click.

It's a bit of a kludge, but it's decidedly easier than mucking about with Javascript.
I somewhat doubt you will be able to keyboard macro, click buttons, or links on a webpage unless that page already setup with JS to listen to keyboard events.

But I guess your creativity depends on what you are comfortable with.
Behold the 'mucking' about it would take to click a button and then click it again after 5 seconds in Javascript.
Code:
document.formName.buttonName.click();
setTimeout("document.formName.buttonName.click()", 5000);
jared_kipe is offline   0 Reply With Quote
Old Dec 17, 2012, 02:13 PM   #5
ytk
macrumors regular
 
Join Date: Jul 2010
Quote:
Originally Posted by jared_kipe View Post
I somewhat doubt you will be able to keyboard macro, click buttons, or links on a webpage unless that page already setup with JS to listen to keyboard events.
Huh? A macro program would just generate a standard HID event, such as a mouse click. The browser (never mind the page) has no way of knowing if that event was generated via software or an actual hardware device. As I understand it, the problem involves simply clicking a button twice in succession. The only reason the second click can't be done manually is because the first click disables the network connection, which is being used to remotely control the computer.

Quote:
Originally Posted by jared_kipe View Post
But I guess your creativity depends on what you are comfortable with.
Behold the 'mucking' about it would take to click a button and then click it again after 5 seconds in Javascript.
Great. Now how do you activate this code on a page that's dynamically generated by a wireless modem and may or may not have names actually assigned to the form and/or button in question?
ytk is offline   0 Reply With Quote
Old Dec 17, 2012, 02:40 PM   #6
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by ytk View Post
Huh? A macro program would just generate a standard HID event, such as a mouse click. The browser (never mind the page) has no way of knowing if that event was generated via software or an actual hardware device. As I understand it, the problem involves simply clicking a button twice in succession. The only reason the second click can't be done manually is because the first click disables the network connection, which is being used to remotely control the computer.



Great. Now how do you activate this code on a page that's dynamically generated by a wireless modem and may or may not have names actually assigned to the form and/or button in question?
How do you position the mouse? I guess I understand what you're going for. You want to pre-position the mouse by hand, and then run a macro to click, and then click again after a min or something, assuming the mouse and button do not move.

The code would be activated by an installed safari extension. http://developer.apple.com/library/s...roduction.html
It is very easy to make an extension, with a single global JS file that would effectively be triggered on every page you visit. Then a simple string compare with document.location.href to make sure you're on the page you want to run it on, and you're golden.


In general, I'd probably look at the page itself and see if the same behavior could be duplicated by just using GET or POST parameters, or visiting a certain URL. If so I'd just script it with wget or curl.

Either way, with only a marginal increase to the time it would take to script or set this up you could have it run every night at 3AM, run when you email yourself a certain subject line etc.
jared_kipe is offline   0 Reply With Quote
Old Dec 17, 2012, 02:21 PM   #7
MasConejos
macrumors regular
 
Join Date: Jun 2007
Location: Houston, TX
Send a message via ICQ to MasConejos
If you are comfortable with html there is a simple programming method you can use.

Assuming this is a page hosted by your router, it probably doesn't have anything fancy going on in the html. Clicking the button probably just sends a post request to the form URL with a parameter. Most scripting languages have something equivalent to an HTTP Request object. You can populate the Request object's properties (url, post paramters, etc) with the information from the webpage.

In effect, you build a script that sends a packet to the router saying that the restart button has been clicked. It will be one simple transaction that can be triggered by a timer or other event and does not requires doing any GUI hooks.

I can walk you through the process if you need help.
MasConejos is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Launch of 'Automatic Link' Smart Driving Assistant Further Delayed MacRumors iOS Blog Discussion 26 Aug 27, 2013 04:52 PM
Nike Twitter Store Link Detector - Auto Link Click/Auto Add To Cart Vizio Community Discussion 0 May 25, 2013 09:18 PM
Is there a script, plugin or program that allows one click image save in Firefox? blueroom Mac Applications and Mac App Store 1 Apr 6, 2013 12:53 PM
Delayed script action haravikk Mac OS X 10.7 Lion 2 Jul 9, 2012 04:26 AM

Forum Jump

All times are GMT -5. The time now is 09:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC