Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chmedly

macrumors newbie
Original poster
Sep 14, 2006
20
0
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.
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
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.
 

ytk

macrumors 6502
Jul 8, 2010
252
5
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.
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
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);
 

ytk

macrumors 6502
Jul 8, 2010
252
5
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.

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?
 

MasConejos

macrumors regular
Jun 25, 2007
149
43
Houston, TX
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.
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
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/...ExtensionGuide/Introduction/Introduction.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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.