[Important note to readers: before trying any of the tips or tools listed on this website, make sure you have a full backup of all data on your computer. These tips have all been tested, but there's always a chance that you'll lose data in the process, so be safe and backup!]
Shell script to toggle AppleTalk between Ethernet and Airport (posted: 10-07-04 11:57 PM)
Being a mobile PowerBook user, I always find myself needing to switch AppleTalk back and forth between Airport and Ethernet, depending on where my printer is, and what kind of network I'm on. I put the following simple bash script together to toggle between AppleTalk and Ethernet (assuming en0 and en1 interface names, respectively), making the switch a one-click process, and saving me lots of trips to System Prefs. Just copy and paste the following into a text file, name the file with the '.command' file suffix, chmod 755, then drop it on your dock, and click on it to toggle AppleTalk.
#!/bin/bash
## If appletalk is off when the script is run, it will be
## enabled on the following interface ("DEFAULT_IF", which is
## set to Ethernet) and will report script feedback using the
## interface name ("DEFAULT_IF_NAME"), so modify these 2 variables
## to your liking:
DEFAULT_IF=en0
DEFAULT_IF_NAME=Ethernet
## no need to edit below here, unless changes are desired
echo 'Checking AppleTalk status...'
echo `appletalk -s` > TAT_TEMP_FILE
ETHERNET_STATUS=`cat TAT_TEMP_FILE | grep 'interface' | grep 'en0' | wc -l`
AIRPORT_STATUS=`cat TAT_TEMP_FILE | grep 'interface' | grep 'en1' | wc -l`
if [ $ETHERNET_STATUS = 1 ];
then
echo "AppleTalk is currently set to Ethernet."
echo "Switching AppleTalk from Ethernet (en0) to Airport (en1)..."
sudo appletalk -d
sudo appletalk -q -u en1
echo "Done! Switch was successful."
rm TAT_TEMP_FILE
exit
elif [ $AIRPORT_STATUS = 1 ];
then
echo "AppleTalk is currently set to Airport."
echo "Switching AppleTalk from Airport (en1) to Ethernet (en0)..."
sudo appletalk -d
sudo appletalk -q -u en0
echo "Done! Switch was successful."
rm TAT_TEMP_FILE
exit
elif [ -s TAT_TEMP_FILE ];
then
echo "AppleTalk is currently disabled."
echo "Enabling AppleTalk on "$DEFAULT_IF_NAME" ("$DEFAULT_IF")..."
sudo appletalk -q -u $DEFAULT_IF
echo "Done! AppleTalk was enabled on "$DEFAULT_IF_NAME" ("$DEFAULT_IF")."
rm TAT_TEMP_FILE
exit
else
echo "Unable to determine AppleTalk status. Now exiting..."
rm TAT_TEMP_FILE
exit
fi