 |
 |
Applescript - Connect to Internet and Safari
|
 |
|
 |
|
Mac Elite
Join Date: Apr 2003
Location: SoCal
Status:
Offline
|
|
Hi all... I'm not sure if this is the right forum to be posting this in, but anyway... I have the following script written up (a combination of scripts that I pulled from MacOSXHints - I don't actually know Applescript):
Code:
tell application "Internet Connect"
set configName to "Internal Modem"
set currentStatus to status of configuration configName
if state of currentStatus is 0 then
connect configuration "Internal Modem"
tell application "iTunes"
activate
end tell
tell application "Mail"
activate
end tell
set the URL_list to {"http://us.imdb.com/StudioBrief/", "http://news.google.com/"}
tell application "Safari"
repeat with i from 1 to number of items in URL_list
set this_URL to item i of URL_list
open location this_URL
end repeat
end tell
else
if state of currentStatus is 4 then disconnect configuration configName
end if
quit
end tell
However, there's one drawback - When it gets to the part of launching the links in Safari, the Internet Connect app usually hasn't finished connecting yet, so I get a "Can't Connect to Server" error. The only thing I can think of is to tell some application that takes an obscenely long time to open (like Fireworks MX) to activate and quit before Safari gets activated, but that seems like too much of a hackish-workaround. Is there any way to tell Safari to not activate until Internet Connect has finished?
Thanks,
-Sage
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Try putting this in before you tell Safari to open the bookmarks:
Code:
repeat while state of status of configuration configName is not 8
delay 1
end repeat
That tells it to wait until the modem reports that it is connected.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Apr 2003
Location: SoCal
Status:
Offline
|
|
That's perfect... Thank you so much! 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
A general tip about the delay statement in AppleScript: it eats CPU like heck. (Instead of being implemented to, say, call sleep() or otherwise yield CPU for a fixed amount of time, it apparently sits in a loop or something.) If you're writing a script that's going to sit in the background waiting for something, this may be an issue.
You can work around this by saving your script as a "say open" application and putting your status checking in an on idle handler. The value you return from this handler is an integer number of seconds until the handler will be called again -- you can use this to moderate your polling.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |