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
Note: The “click the menu item…” is highlighted after I close the error message box.
tell application "Internet Connect"
tell application "System Events"
tell window 1 of process "Internet Connect"
tell button "Airport" of tool bar 1
--for my benefit during testing
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.
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?
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.
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.