Your help is appreciated

Sep 29, 2005 19:23

I wish to write a simple script that loads Safari and Mail upon connecting to the internet (by dial-up) and checks for new mail.
The problem is that after

tell app "Internet Connect" to connect

the script doesn't wait until the connection is established.
How can I make it wait?

Leave a comment

Comments 5

ranger1 September 29 2005, 22:08:44 UTC
I think you can test the "seconds connected" value of Internet Connect's "status" property. If "seconds connected" is less than zero, then you aren't connected.

Incidentally, I get a strange result when I check that value on my computer:

Script: tell application "Internet Connect" to get seconds connected of status
Result: -2.147483648E+9

I know it's because my computer is connected by Ethernet instead of dial-up. But I would've expected Internet Connect to return a "missing value" instead of a wacky negative number. I wonder where it gets that number.

Reply

threeeyedfish September 30 2005, 03:41:36 UTC
Thank you very much!
As for the negative number, maybe that's because the property exists, but has not been initialized?

Reply

threeeyedfish October 1 2005, 14:50:59 UTC
Well, but if I check immediately after connecting using "if", my script will be never executed!
Is there any syntax like
wait until (seconds connected of status>0) or something like that?
Maybe this question is foolish, but exuse me, I'm using Mac for less than a month.

Reply

ranger1 October 1 2005, 18:00:51 UTC
"repeat until" or "repeat while" would probably fit the bill:
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.b8.html

Maybe something like this:

tell application "Internet Connect"
repeat until (seconds connected of status) > 0
delay 1
end repeat
end tell
--rest of script here

You might want to add a second condition to the repeat loop, to keep the script from running forever when the modem is unable to connect. For example:

set max_number_of_checks to 30
set number_of_checks to 1
tell application "Internet Connect"
repeat until ((seconds connected of status) > 0) or (number_of_checks > max_number_of_checks)
delay 1
set number_of_checks to number_of_checks + 1
end repeat
end tell
if (number_of_checks = max_number_of_checks) then return
--rest of script here

Adjust max_number_of_checks to the number of times it should check on the modem status.

Reply


Leave a comment

Up