Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to automatically reconnect to the net Internet
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:
  • Open the browser (if not already connected, it is redirected to a login homepage).
  • Select the "user" field and type the username.
  • Select the "password" field and type the password.
  • Select the "provider" field and choose the provider from a list (it is enough for me to type the letter "O").
  • Select the "OK" button and hit the enter key.
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.
    •    
  • Currently 1.50 / 5
  You rated: 1 / 5 (4 votes cast)
 
[11,472 views]  

An AppleScript to automatically reconnect to the net | 5 comments | Create New Account
Click here to return to the 'An AppleScript to automatically reconnect to the net' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to automatically reconnect to the net
Authored by: comodin on Apr 07, '06 08:26:21AM
i do not understand why u need your browser to open the internet-connection. for me a simple ping will open the line.

for a cronjob:

#!/bin/sh
ping -c 1 google.com
or for a iCal-event:

try
    do shell script "ping -c 1 google.com"
end try
:)

---
--


[ Reply to This | # ]

An AppleScript to automatically reconnect to the net
Authored by: DeltaTee on Apr 07, '06 09:18:09AM

If you have to go to a web page and type in a password, you would need a script like this. Ping won't work: the computer can no longer connect to the internet.



[ Reply to This | # ]
An AppleScript to automatically reconnect to the net
Authored by: DocMan on Apr 07, '06 10:33:00AM

To quickly and easily set up cron jobs, look at Cronix (or is it Cronnix?). It has a GUI interface that lets you set up items in both the system and the user cron tables.

Doc



[ Reply to This | # ]
An AppleScript to automatically reconnect to the net
Authored by: t413 on Apr 07, '06 03:07:03PM
here is the link to the CronniX web site. I use it every once and a while, it is a great app.

[ Reply to This | # ]
An AppleScript to automatically reconnect to the net
Authored by: T0Bi on Apr 09, '06 04:13:17AM

You could use CURL (http://curl.mirror.at.stealer.net/docs/httpscripting.html
) to do a POST.

curl -d "user=username&password=mypassword" www.hotmail.com/login.cgi

If you use e.g. wget (install via fink) to test if there ist still a internet connection - like in this script i just found by googling - you can run it continuously. This script takes also care of https and cookies if needed.
-------
[code]
#!/bin/bash
# Script to auto-login to UMN Resnet
#
# Written by Matthew Beckler beck0778@umn.edu

USERNAME=beck0778
PASSWORD=password
COOKIEJAR='/tmp/resnet-cookie'

wget http://www.google.com/ -O /dev/null &> /dev/null
if [[ $? = 1 ]]; then
#could not access google.com - time to login
curl https://resnet.netsec.umn.edu/fall2005/?original=http://www.google.com/ -F username=$USERNAME -F password=$PASSWORD -c $COOKIEJAR -L -o /dev/null &> /dev/null
#waiting 30-120 seconds - you might want to adjust this
sleep 30
#finalize the login
curl https://resnet.netsec.umn.edu/fall2005/ -b $COOKIEJAR -L -o /dev/null &> /dev/null
fi

exit 0
[/code]
--------



[ Reply to This | # ]