Who can do me an AppleScript (Internet Connect) favor?

Hi,

I ordered “The missing Manual” but I think I will not solve my actual problem until Friday when I go on holiday for 2 weeks.

Can someone tell me how I connect Internet Connect all 25 hours using AppleScript?

(My provider disconnects after 24 hours and I have the idea to use the holidays for a download.)

Thanks in advance, if someone can help me.

Presumably all you need is some internet activity to stay online. If pinging an external address is enough and you know how to write an “on idle” handler set to return every 23 hours or so, this line will do:

set intnt to do shell script "ping -c 1 63.208.196.110"

If a ping isn’t enough, then getting a web page in your idle handler might be better:

set theHTML to my get_url("checkip.dyndns.org")

on get_url(this_url)
	set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
	return do shell script "curl " & (quoted form of this_url) & " -A " & browser_string
end get_url

Hi,

first at all: Thank you very much!

I’m in this stuff now only for some minutes, but maybe it is helpful that I was in Macromedia’s ActionScript a little bit (2 or 3 books about it).

As for the moment I am curious if the following would work too (and if it will run endlessly until I quit the application AppleScript Script Editor):

on idle "Internet Connect"
	connect
	return 60
end idle

Hi, August. I don’t think “connect” is an applescript command - you have to do something that requires the internet so the system will connect. Also, idle handlers don’t have names - there can be only one in a script. If you want a label in the form of a comment use two dashes: – Internet Connect.
Finally, AppleScripts normally quit when their work is complete. To make them stay open you have to save them as Stay Open applications (options under save as…) and you’ll have to quit them from another script or from the Activity Monitor.

on idle
set theHTML to my get_url("checkip.dyndns.org")
return 3600  -- this is in seconds. Once an hour should be fine.
end idle

on get_url(this_url)
   set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
   return do shell script "curl " & (quoted form of this_url) & " -A " & browser_string
end get_url

I have not yet read your answer!

I found out that the following script works:

tell application "Internet Connect"
		connect
	end tell
	return 10

But it does not work if I try to run it endlessly, like this:

on idle
	tell application "Internet Connect"
		connect
	end tell
	return 10
end idle

Now I will read your answer!

In my system (Panther 10.3.9) Internet Connect doesn’t have a dictionary (in fact trying to open its dictionary crashes my Script Editor), but that doesn’t mean IC won’t respond to the command. I don’t know why your idle handler won’t work when the straight-up script (which doesn’t need the return 10) does.

I don’t have a DSL connection so I can’t try any of these (I’ve got a 10 Mbit/sec cable connection that’s online 24/7).

It’s possible that it crashes because “Internet Connect” is already connected. I played quite a while with that app a year ago and in the end all I used was something like:


on run
	tell application "Internet Connect" to connect -- or not... if you'll run the script while already connected
end run

on reopen
	display dialog "Quit?" buttons {"No", "Yes"} default button 1 with icon stop giving up after 5
	if button returned of the result is "Yes" then tell me to quit
end reopen

on idle
	try
		tell application "Internet Connect"
			if state of status of current configuration is not equal to 8 then connect -- that is, if not connected.... connect! Found out trying and logging a lot...
		end tell
		-- close window 1 -- if you want to get it out of the way...
		-- tell application "System Events" to set visible of process "Internet Connect" to false
	end try
	return 3600
end idle

on quit
	ignoring application responses
		tell application "Internet Connect" to quit -- or not... your choice.
	end ignoring
	continue quit
end quit

“connect” is an applescript command when inside a tell app “Internet Connect” block. Of course, you’d have to save your script as a stay open for any of the above handlers to work (excepting ‘on run’). I didn’t test it exactly as is, but it should work… Hope it helps.

Wow. More lines as I expected, but, hey, it works.

shout
Thank you
/shout

Btw, I really and truly have to get behind this - hope the book (The Missing Manual) will entertain me, when I am on holiday.

I have been working on a similar problem. I found some code that I have since adapted to automatically connect my VPN whenever an active network connection is detected.

My problem is that if Internet Connect is not set to the VPN screen, then the connect command makes it try to dial the modem or connect to an AirPort or some other unwanted activity.

How can I tell Internet Connect to change to the VPN mode, or simply tell it to connect that.
I also seem to be unable to tell it what configuration to use.

Thanks.

I checked the dictionary for Internet Connect and found this:

so you might try something like:

tell app "Internet Connect" to connect VPN Configuration

or:

tell app "Internet Connect" to connect using VPN Configuration

Haven’t tried any of these, but it might work. I remember reading something about this some time ago.

Sorry for the short answer, but I’m on vacations… finaly!! Saludos!

Thanks for the help. Unfortunately both ideas seem to just throw errors.

I haven’t got any VPN network so I didn’t know which one you needed… but this worked… at least “Internet Connect” threw a “server not found” error.


tell app "Internet Connect" to connect configuration (get name of PPTP Configuration 1) -- or <L2PT Configuration> or whatever you have... check the dictionary!

It seems that Internet Connect connects by configuration name, not class. I created an empty PPTP configuration and it worked, apart from the error that no connection could be made since I had no current connection to the internet. If you have more than one just specify it’s name and it should work.

If it doesn’t… I give up…

Perfect! Many thanks!