I need a way to enable my Airport Internet connect without the GUI.
There is
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 300 --delay in seconds
tell button "Turn AirPort On"
click
end tell
end tell
end tell
end tell
delay 3
tell application "Internet Connect" to quit
from several previous posts here but that is broken on my machine, gives:
“AppleScript Error”. “System Events got an error: NSReceiverEvaluationScriptError: 4”.
The following is more useful for me to turn off Airport. Avoids the distraction of Internet Connect flashing onto the screen too:
set AirportData to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z"
The idea was in a post somewhere here (thanks) and it sent me investigating that “framework” in terminal. Turns out it supports a “-h” and “-x” to list all operators.
What I need is exactly the same only to connect!
Hi, some places don’t tolerate successive posts as it’s treated as bumping so hope I’m not out of order here…
I am part way to solving the problem:
do shell script "sudo ifconfig en1 up"
will succeed in pulling the network connection through my Airport Extreme back up. But it requires my admin password. This script will NOT be run by me.
I need a solution that doesn’t require sudo.
I have checked my system logs for when I manually used ifconfig to pull the connection down and then back up: Identical as though one of my mysterious droputs/disconnections had occurred.
So all I need is a sudo workaround?
Forgive me for patronising: This place rocks! So much Apple Script wisdom all in the one place.
Another edit with my progress:
From the terminal, if I enter:
/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -A’MyHomeNet’ BSSID=‘00:11:22:33:44:55’ then I get prompted for the password of the network. I enter that and my connection is restored. Excellent. Took me a lot of experimenting to nut out the syntax.
If I do this from an Apple Script I will need to enter a password. But this is for other people to use. So I’m still stuck with passwords. Still looking for a work around.
Hi,
you can include the password in the do shell script line
do shell script "ifconfig en1 up" password "myPW" with administrator privileges
Thanks but I wasn’t very clear - I am worried about my password being found out - I’ve never had my password appear in plain text - ever. So I’m very uncomfortable with that.
What I don’t understand is that through the GUI a password is not necessary. That’s why I just know there is a non-GUI solution somewhere in OSX. Somewhere…
According to your investigations, this works on my machine
do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -A'MyHomeNet' --password=¢¢¢¢¢¢¢"
Works for me too. I guess I have to become comfortable with placing a password into the script. I can “Compile” into a bundle and that will hide the password a little bit. My point was trying to find some way of not doing this.
My reasoning is simple: If I can select the network from my menu bar, via the Airport icon, and reconnect without a password then there must be a way of doing this with a script. So I can move on, I will use the password for now.
Thanks
The airport menu uses the keychain to get the password.
maybe it’s possible to do the same with keychain scripting
That’s an idea. Not sure how to do that. Any suggestion in that respect thankfully received!
Would I invoke a “Tell application keychain” block, select the password and then inside that block invoke a Airport related shell script?
something like this
property BSSID : "myHomeNetwork"
tell application "Keychain Scripting" to set myKey to password of first key of current keychain whose name is BSSID
do shell script "/usr/sbin/networksetup setairportnetwork " & BSSID & space & myKey -- a shorter version instead of calling the framework executable
Absolutely brilliant!
Sorry to ask for the answer. The “/usr/sbin…” bit is something totally new for me.
I’m now working on three separate Scripting projects. With the ability to script the GUI and just about anything we really do have a lot of power at our disposal. Rather than just wishing for something from my Mac I can actually get about and program it myself!
Thanks heaps!
Edit: Just discovered that /usr/sbin is where lots of great terminal commands are kept. My God the power is going to my head
Heck, diskutil looks very dangerous! But useful too.