Scripting Internet Connect

I’m a noob and this is my first attempt at scripting.
My goal is to write a script that opens Internet Connect, clicks the AirPort tab, and clicks the “Turn AirPort Power Off” button (assuming the power is on).
Then it waits 3 seconds, and clicks the “Turn AirPort On” button.

Why? Sometimes my laptop wakes up and forgets how to connect to the wireless network. Turning the AirPort on and off frequently saves me from having to go upstairs and manually restart the router.)

When I run my script I get “NSReceiverEvaluationScriptError: 4”
Here’s what I’ve pieced together so far:

tell application “Finder”
open application file “Internet Connect.app” of folder “Applications” of startup disk
tell application “System Events”
tell process “Internet Connect”
click the menu item “Turn AirPort Off” of the menu “AirPort” of menu bar 1
end tell
end tell
end tell

Note: The “click the menu item…” is highlighted after I close the error message box.

Greetings from another noob.

How’s this?


tell application "Internet Connect"
	activate
	tell application "System Events"
		tell window 1 of process "Internet Connect"
			tell button "Airport" of tool bar 1
				click
			end tell
		end tell
	end tell
end tell

--for my benefit during testing
delay 3
tell application "Internet Connect" to quit

I noticed my attempts didn’t work if “Internet Connect” is not already running. I added the bit about quitting in case I forgot to quit “Internet Connect” before testing.

I started to add clicking the button to turn “AirPort” off then on, depending on its status, but I have other things that need doing first. You might want to keep the quit command if you do that.

j

Looking at the dictionary for Internet Connect, it seems this should work:


tell application "Internet Connect"
	set AirPort power of AirPort configuration 1 to false
	delay 3
	set AirPort power of AirPort configuration 1 to true
end tell

It doesn’t work on my Intel Mac. Getting stuff like the name of the configuration doesn’t work either.

I had a couple of free minutes, so


tell application "Internet Connect"
	activate
	tell application "System Events"
		
		tell window 1 of process "Internet Connect"
			tell button "Airport" of tool bar 1
				click
			end tell
			
			tell button "Turn Airport Off"
				click
			end tell
			delay 3
			tell button "Turn AirPort On"
				click
			end tell
			
		end tell
	end tell
end tell

delay 3
tell application "Internet Connect" to quit

It works on my PowerBook.

Without thinking I ran the script while posting and although the AirPort icon changed to reflect being turned off then on, I didn’t become disconnected from the internet. Maybe it changes too quickly?

EDIT: I was only connected using AirPort.

j

Hey, capj;

Welcome as a poster of solutions! That’s how this community grows.

Adam

Thanks.

I’m benefiting from the forum so I’m happy to contribute when possible; challenging myself with another’s problem is a good way to learn.

j

Thanks Capital J.
Your noobishness is clearly not hindering you from writing scripts that work.
I tried yours and it performed flawlessly.
What I called a “menu item” you called “window 1” and Internet Connect listened.
Any tips on where can I find out more about system events?
-G

I’m glad it helped.

I had a similar problem, but it turned out that my modem/router was not fond of Macs. It took some doing, but my isp finally agreed to replace it with a better one.

As for scripting System Events, there is its dictionary (of limited use to me because of my limited knowledge, but becoming more useful as I learn more) and seaching this forum. My wife has begun to comment on the frequency of dings she hears because I subscribe to so many threads. There are plenty of books, too.

UIElementInspector is useful - http://developer.apple.com/samplecode/UIElementInspector/index.html

j

I’ll check it out.
Look forward to seeing your future postings.
-G

Gyuen,

Thank you, thank you, thank you. I have been fighting Internet Connect for a year trying to get the da*&%n thing to turn airport off (on). Perhaps it is the fact that I’m on Jaquar, but it absolutely will not recognize button, tool bar, or menu. It would either convert them to varialbles, or complain about the quotation marks.

Your problem was my solution. I am in your debt. :slight_smile: :slight_smile: