I've written a script that removes our corporate WiFi network and then re-adds it as the top preferred network.
When I run the script on a client through Casper Remote, it works as expected.
When I run it as a policy through Self Service, I get asked to allow networksetup (the binary that is doing the work in the script) to access the keychain item for the WiFi network. Any help? The script is below.
#!/bin/bash
# Script for to set the preferred wifi SSID and/or remove an unwanted SSID
# $4 is the SSID you want to make the preferred network.
# $5 is the SSID you want to remove from the list of preferred networks
# These variables are passed in by Casper--set them in Casper Remote or in policy settings, depending on how you're deploying the script
# Set the SSID specified in $4 as the preferred network by removing it and re-adding it
if [ -z "$4" ]
then
echo "No preferred SSID has been passed into the script, skipping this step..."
else
echo "Setting $4 as the preferred WiFi network..."
wifi=`networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/,/Ethernet/' | awk 'NR==2' | cut -d " " -f 2`
/usr/sbin/networksetup -removepreferredwirelessnetwork $wifi $4
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $wifi $4 0 WPA2E NONE
fi
# Delete the SSID specified in $5
if [ -z "$5" ]
then
echo "No SSID is set to be deleted"
else
ssidToDelete=`networksetup -listpreferredwirelessnetworks $wifi | grep $5`
if [ -z "$ssidToDelete" ]
then
echo "$5 isn't set up on this computer"
else
/usr/sbin/networksetup -removepreferredwirelessnetwork $wifi $ssidToDelete
fi
fi