An AppleScript to automatically reconnect to the net

Apr 07, '06 06:12:00AM

Contributed by: enzo sparacino

I leave my PowerBook G4 (running OS X 10.4.5) mainly unattended, and I want to be able to access it remotely; to do that, it has to be always online. From time to time, my Internet connection drops and I've come up with an AppleScript which reconnects to the Internet by performing all the necessary tasks. The script is launched automatically every half an hour by iCal (a crontab would be an excellent alternative ... maybe I'll try it later on).

The multi-step procedure to reconnect is the following:

In the Universal Access preferences pane, I checked the box at the bottom that says "Enable access for assistive devices" to enable the "System Events." The code I came up with is the following:
set CR to ASCII character of 13

tell application "System Events"
  tell application "Camino" to activate
  delay 30
  keystroke tab & tab & tab & [username] & tab & ¬
   [password] & tab & "O" & tab & CR
  delay 20
  tell application "Camino" to quit
end tell

end
I am using Camino as browser. The Tab keys are used to navigate through the fields of the login homepage; [username] and [password] in the script are replaced by my real username and password. The O is the key to digit after selecting the field containing the list of providers. The script is my first attempt to use AppleScript. It works.

I am pretty sure that there are many possible improvements and alternatives -- which I will be glad to learn from you.

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060403003036779