Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript - Connect to Internet and Safari

Applescript - Connect to Internet and Safari
Thread Tools
Mac Elite
Join Date: Apr 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 22, 2003, 03:09 PM
 
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
Reply With Quote
Nov 22, 2003, 04:37 PM
 
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'."
     
Sage  (op)
Mac Elite
Join Date: Apr 2003
Location: SoCal
Status: Offline
Reply With Quote
Nov 22, 2003, 06:18 PM
 
That's perfect... Thank you so much!
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 24, 2003, 07:11 PM
 
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.
Rick Roe
icons.cx | weblog
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:27 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2