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
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
As for the negative number, maybe that's because the property exists, but has not been initialized?
Reply
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
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