Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Mount and unmount server shares via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Mount and unmount server shares via AppleScript
Authored by: scatlin on Mar 21, '05 12:00:50PM
I've been working on a script to automagically set my Network Location and therefore my IP address(es). Here's an AppleScript command to get your IP address via ifconfig that I've used:

set EthernetIPAddress to do shell script "ifconfig en0 | awk '/inet / {print $2}'"

You can modify it based on what interface (en0, en1, etc.) you want to get the IP for. In my case, en0 is my built in ethernet and en1 is my AirPort.

[ Reply to This | # ]

Mount and unmount server shares via AppleScript
Authored by: CkB_Cowboy on Mar 21, '05 03:58:56PM
I've written a simple bash script that outputs a space-delimited list of all IP addresses bound, across all ethernet adapters. You can either call the script by itself to return that list, or pass it an IP address as the sole argument, in which case it returns the IP address if it's bound, or nothing if it isn't.

Check it out:
#!/bin/bash

# echo a list of all bound IPs
#

ISIP_TEMP=`ifconfig -u | grep -w "inet" | awk '{printf " " $2}'`

if [ $1 ]; then
	if [ -n "`echo $ISIP_TEMP | grep -w $1`" ]; then
		echo $1
	fi
else
	echo $ISIP_TEMP
fi

unset ISIP_TEMP

I actually use this script in a handful of other scripts. I hope it's helpful!

- Cowboy

---
My ill-matic homepage:
http://rj3.net/cowboy/

[ Reply to This | # ]

an example:
Authored by: CkB_Cowboy on Mar 21, '05 04:17:02PM
I thought I'd provide an example of usage. I named the script in the parent post isip, put it in the path, and made it executable, so it's accessible to any of my scripts.


#!/bin/bash

if [ `isip 192.168.0.70` ]; then
        open ~/bin/myscript_network_home
else
        open ~/bin/myscript_network_work
fi

Since I've configured my home DHCP server to reserve 192.168.0.70 for my laptop, and that address doesn't fall into the DHCP pool at work, this script can easily tell which network I'm on and run the right app, automagically!

- Cowboy

---
My ill-matic homepage:
http://rj3.net/cowboy/

[ Reply to This | # ]