Este truco nos ha venido perfecto en redacción, justo porque nos ha cogido en una situación similar: en casa se usa en Airport, pero en el trabajo, con el mismo ordenador, una red ethernet. Aunque hay una red Airport disponible en el trabajo, depende de un router que se cae con frecuencia, así que no te das cuenta, conectas tu cable ethernet (pero se ha conectado Airport primero de forma automática) y en mitad de un envío importante te das cuenta que
ping 192.168.0.1 es igual a cero
Para solucionar este problema, podemos usar un script, una preferencia y listo.
Coge este script y mételo en un archivo de texto puro para guardarlo omo Airport.sh en /Library/Scripts
function set_airport {
new_status=$1
if [ $new_status = «On» ]; then
/usr/sbin/networksetup -setairportpower en1 on
touch /var/tmp/prev_air_on
else
/usr/sbin/networksetup -setairportpower en1 off
if [ -f «/var/tmp/prev_air_on» ]; then
rm /var/tmp/prev_air_on
fi
fi
}
function growl {
# Checks whether Growl is installed
if [ -f «/usr/local/bin/growlnotify» ]; then
/usr/local/bin/growlnotify -m «$1» -a «AirPort Utility.app»
fi
}
# Set default values
prev_eth_status=»Off»
prev_air_status=»Off»
eth_status=»Off»
# Determine previous ethernet status
# If file prev_eth_on exists, ethernet was active last time we checked
if [ -f «/var/tmp/prev_eth_on» ]; then
prev_eth_status=»On»
fi
# Determine same for AirPort status
# File is prev_air_on
if [ -f «/var/tmp/prev_air_on» ]; then
prev_air_status=»On»
fi
# Check actual current ethernet status
if [ «`ifconfig en0 | grep «status: active»`» != «» ]; then
eth_status=»On»
fi
# And actual current AirPort status
air_status=`/usr/sbin/networksetup -getairportpower en1 | awk ‘{ print $4 }’`
# If any change has occured. Run external script (if it exists)
if [ «$prev_air_status» != «$air_status» ] || [ «$prev_eth_status» != «$eth_status» ]; then
if [ -f «./statusChanged.sh» ]; then
«./statusChanged.sh» «$eth_status» «$air_status» &
fi
fi
# Determine whether ethernet status changed
if [ «$prev_eth_status» != «$eth_status» ]; then
if [ «$eth_status» = «On» ]; then
set_airport «Off»
growl «Wired network detected. Turning AirPort off.»
else
set_airport «On»
growl «No wired network detected. Turning AirPort on.»
fi
# If ethernet did not change
else
# Check whether AirPort status changed
# If so it was done manually by user
if [ «$prev_air_status» != «$air_status» ]; then
set_airport $air_status
if [ «$air_status» = «On» ]; then
growl «AirPort manually turned on.»
else
growl «AirPort manually turned off.»
fi
fi
fi
# Update ethernet status
if [ «$eth_status» == «On» ]; then
touch /var/tmp/prev_eth_on
else
if [ -f «/var/tmp/prev_eth_on» ]; then
rm /var/tmp/prev_eth_on
fi
fi
exit 0
Ahora hay que hacerlo ejecutable, así que abre el terminal, en Aplicaciones > Utilidades y escribe
chmod 777
y arrastra el archivo al Terminal. Pulsa Enter y con eso el script podrá ejecutarse.
Ahora vamos a crear una preferencia:
Crea un archivo de texto puro y añade el siguiente código:
<!DOCTYPE plist PUBLIC «-//Apple//DTD PLIST 1.0//EN» «http://www.apple.com/DTDs/PropertyList-1.0.dtd»>
<plist version=»1.0″>
<dict>
<key>Label</key>
<string>com.asb.toggleairport</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/toggleAirport.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
</dict>
</plist>
Guárdalo en /System/Library/LauchAgents/ con el nombre de archivo com.mine.toggleairport.plist
.
Ahora, cuando conectes tu cable ethernet, tan pronto como el sistema reconozca la conexión, desactivará Airport. Recuerda que si activas Airport después de conectar el cable ethernet de forma manual, el script no volverá a desconectarlo.
Fuente: mac OS X Hints
Preferencias del Sistema—>Red—>Establecer orden de servicios (click en el engranaje de la parte de abajo de la columna de interfaces de red)
Arrastras Ethernet por encima de Airport y ya está.
¿Existe la posibilidad de asignar una conexión determinada a una aplicación específica?. Es decir, asignar la conexión ethernet a Safari y la inlalámbrica a Firefox.
Saludos.
Es un simple comentario, pero es mío.
Empecé a escribir sin comentarios previos y acabo de ver el tuyo. Muchas gracias.
Es un simple comentario, pero es mío.
Muchissimo mas sencillo lo que se explica en el primer comentario de mikeunimac
nop. Lo que puedes hacer es decir q cuando tu maquina se conecte a ciertos rango de direcciones, los paquetes se envien por una determinada interfaz. Pero que yo sepa no puedes configurar eso a nivel de aplicacion.
muy bueno, no conocía esta opción
ahh, ya me parecía. Eso era más sencillo y lo que vengo usando hace tiempo.