Posted on 09-08-2011 10:44 AM
Hi guys,
I used a slightly modified version of the turn airport off script from the resource kit to.. erm.. turn off the airport.
It looks like apple have "fixed" 10.7, so instead of issuing:
/usr/bin/networksetup -setairportpower *HardwarePortName* off
You now need to do the following:
/usr/bin/networksetup -setairportpower *DeviceName* off
*DeviceName* is listed when you run,
/usr/sbin/networksetup -listallhardwareports
So i tried:
/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: "$checkWireless"/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-
where checkWireless is set using the following:
checkWireless=$(networksetup -listallhardwareports | egrep "Hardware Port: (Air|Wi-)" | cut -c 16-)
But the variable does not seem to be passing. script below.. maybe there is a better way?
In context below:
if [[ "$OS" == "10.4" ]]; then
# If OS is 10.4.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower off
exit 0
elif [[ "$OS" == "10.5" ]]; then
# If OS is 10.5.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower off
exit 0
elif [[ "$OS" == "10.6" ]]; then
# If OS is 10.6.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower "$checkWireless" off
exit 0
elif [[ "$OS" == "10.7" ]]; then
# If OS is 10.7.x run the following to turn off Wireless...
checkWireless=$(networksetup -listallhardwareports | egrep "Hardware Port: (Air|Wi-)" | cut -c 16-)
# First we need to get the Wi-Fi device's name
wifiDevice=/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: "$checkWireless"/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-
echo "Wi-fI Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower "$wifiDevice" off
exit 0
fi
Posted on 09-08-2011 12:05 AM
Nvm.
Thinking about this the name returned from /usr/bin/networksetup -listallhardwareports for the wireless card will always be Airport pre 10.7 & Wi-Fi on 10.7.
So no need for this step.
Regards,
Ben.
Posted on 09-08-2011 10:50 AM
/usr/sbin/networksetup -setnetworkserviceenabled Wi-Fi off
Allen
Posted on 09-08-2011 11:07 AM
That will disable the service right?
I'm merely looking at turning off the airport.
Regards,
Ben.
Posted on 09-08-2011 11:16 AM
Yeah, that disables it. On my firstboot if its not a notebook it gets disabled.
Thanks
Allen
Posted on 09-08-2011 10:23 PM
unless of course somebody renames it, because they like airport better.
--
Todd Ness
Technology Consultant/Non-Windows Services
Americas Regional Delivery Engineering
HP Enterprise Services
Posted on 09-08-2011 10:31 PM
The hardwareport name is what the OS is calling the Wireless device.
The service is what's renamable.
Regards,
Ben.
Posted on 09-09-2011 02:17 AM
Script has been posted here: http://wp.me/p12A66-55
This script will:
1. Enable the wireless service if it's not been enabled.
2. Clear any set DNS servers & search domains (can be turned off for 10.4, reasoning is that 10.5+ can receive DNS from DHCP)
3. Turns off the wireless card.
The script itself has been built from a few scripts contained within Caspers Resource Kit & then modified for 10.7 by myself.
Works on 10.4+ & can help those with slow ad logins when off the office lan, http://wp.me/p12A66-2Z
Posted on 09-12-2011 04:29 AM
networksetup will allow you to use either "Hardware Port:" or "Device:" to turn the power on or off
Hardware Port: AirPort Device: en2
You can pull the device name from ioreg, regardless of OS, so it doesn't matter that Lion calls it one thing and previous versions another.
ioreg -l -n ARPT at 0 -r | grep "BSD Name" | cut -d """ -f 4
Sean
Posted on 09-12-2011 05:35 AM
thanks Sean!
However, it does see, that on 10.7 it has to be "Device" & not "Hardware Port"
Even the man pages are confuseds though as in the man page synopsis it seems to show this behaviour: [-setairportpower device on | off]
but in the description it says:
-getairportpower hardwareport Displays whether Wi-Fi power is on or off.
Maybe i'll file a bug report...
Posted on 09-12-2011 06:34 AM
That may be related to ioreg not having an equivalent to "AAPL,slot-name" for the wireless device.
Snow Leopard and Leopard have: "AAPL,slot-name" = <"AirPort">
Lion has nothing to match this. Probably worth mentioning if you are going to bug report it.
Sean