Hi. I’ve been trying to find an Applescript or shell script using /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport that will let me simply join an Airport network using the password in the keychain. All the info I can find is for Tiger or earlier OSes. Why is this so difficult? Or am I just dense? Or both?
Model: MacBook Pro
Browser: Firefox 3.0.6
Operating System: Mac OS X (10.5)
Hi,
try this
property BSSID : "myWirelessNetwork"
tell application "Keychain Scripting" to set myKey to password of first key of current keychain whose name is BSSID
do shell script "networksetup setairportnetwork " & BSSID & space & myKey
Thanks for the prompt reply, Stefan. At first I ran the script and got a permission error:
So I just went to Terminal and did
and I got:
In any event, I’d like to avoid having to enter a password, just use the keychain
Also, thanks for tipping me to the networksetup command, all sorts of goodies there.
strange, the script works flawlessly on my machine (in an admin account)
The first time you will be asked to confirm the keychain, but then no further password is required
Strange indeed. I repaired permissions and restarted, and still the same problem. I will try it out later on another computer, to see if it’s just a problem on this one. Thanks
Same permission error on the G5. Hmmm…
I was able to execute from the terminal with sudo, but that kind of kills the point.
I am logged in as admin.
Still getting permissions error, but then more strange behavior:
When I run Stefan’s script as root, I get the “** Error: Error obtaining wireless information.” error.
First I checked if myKey is getting the correct password and it is.
So I tried just doing it straight up, just filling in the password and SSID within the script directly. That worked. A Ha!
So I tried this:
property BSSID : "myNetworkID"
tell application "Keychain Scripting" to set myKey to password of first key of current keychain whose name is BSSID
do shell script "sudo networksetup -setairportnetwork " & quoted form of BSSID & space & quoted form of myKey
That worked. No more permissions errors either.
Thanks again Stefan
Sudo should not be used with “do shell script”. The preferred form is
set tResult to do shell script "my shell stuff" with administrator privileges