We recently acquired one of the new MacBook's in our environment, and due to the USB-C port opted to manually configure it rather than image, as our imaging method only works via ethernet at the moment. For some reason the laptop would not reconnect via WiFi after waking the computer from sleep. Specially the 802.1x component failed to reconnect (we use PEAP in our environment).
The user of the computer is technical and was trying to use AppleScript to automatically reconnect, but could not find a way to specify the "Connect" button in Network Preferences. Modifying a script I found here, this worked for him. He suggested I pass it along as we came across others in the wild with a similar problem, and the link listed above was a little tricky to find. Hope someone finds it helpful.
do shell script "/usr/sbin/networksetup -setairportpower en0 on"
delay 2
tell application "System Preferences"
activate
reveal pane id "com.apple.preference.network"
reveal anchor "Wi-Fi" of pane id "com.apple.preference.network"
end tell
tell application "System Events"
tell window 1 of process "System Preferences"
click button 2 of group 1
if title of button 2 of group 1 begins with "Connect" then
click button 2 of group 1
end if
end tell
end tell
