On the MacBook Airs and Retina MacBook Pros, the WiFi port is en0 and not en1. I've got a script available that helps sort that out automatically:
#!/bin/sh
#
# Please see the accompanying README for
# an explanation of what this script is for.
#
# Hat tip to Charles Edge for describing this
# method in this entry on his blog:
# http://krypted.com/mac-os-x/pushing-wireless-networks-out/
#
# Enable the wireless method you need and
# add the correct variables as needed. The
# wireless network name should not contain spaces.
# Determines which OS the script is running on
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
# On 10.7 and higher, the Wi-Fi interface needs to be identified.
# On 10.5 and 10.6, the Wi-Fi interface should be named as "AirPort"
wifiDevice=`/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: Wi-Fi/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-`
# Set the SSID variable to your wireless network name
# to set the network name you want to connect to.
# Note: Wireless network name cannot contain spaces.
SSID=
# Set the INDEX variable to the index number you’d like
# it to be assigned to (leave it as "0" if you do not know
# what index number to use.)
INDEX=0
# Set the SECURITY variable to the security type of the
# wireless network (NONE, WEP, WPA, WPA2, WPAE or
# WPA2E) Setting it to NONE means that it's an open
# network with no encryption.
SECURITY=
# If you've set the SECURITY variable to something other than NONE,
# set the password here. For example, if you are using WPA
# encryption with a password of "thedrisin", set the PASSWORD
# variable to "thedrisin" (no quotes.)
PASSWORD=
# Once the running OS is determined, the settings for the specified
# wireless network are created and set as the first preferred network listed
if f ${osvers} -ge 7 ]]; then
networksetup -addpreferredwirelessnetworkatindex $wifiDevice $SSID $INDEX $SECURITY $PASSWORD
else
networksetup -addpreferredwirelessnetworkatindex AirPort $SSID $INDEX $SECURITY $PASSWORD
fi
It's also available here on my Github repo:
https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/setting_preferred_wireless_networks
Why not use a config profile?
As Ben says, I find it easier to generate a config profile (using iPhone Configuration Utility, Apple Configurator or Casper and manually download it), package this up into an installer that dumps it into /tmp/ and use a script, such as the below, to install it.
Works fine when I've had to use it
#!/bin/sh
profiles -I -F /tmp/[profile name]
sleep 2
rm /tmp/[profile name]
exit 0
I definetly would recommend a config profile which is installed during imaging process. That's what I use here and it works like a charm.
Thanks for the help. I've tried as recommended using a config profile, but it's been inconsistent. It will connect after the first boot, but sometimes won't after a restart. It will also disconnect and will not reattach after going to sleep. This whole thing has been beyond frustrating. Trying it using just the post install will not work at all (rtrouton's posted script).
Thanks again.
@ Mike did you ever get anything done with this? I use Tim Sutton's make-profile-pkg (https://github.com/timsutton/make-profile-pkg) and install the wifi profile at reboot. It's the only way I could get it to work so students could log in using LDAP credentials from first boot on a non-booted image.