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

Mount and unmount server shares via AppleScript Network
I am using a fileserver at home, and various SMB shares at my university, so I needed a script that automatically mounts the appropriate shares, or unmounts those that are already mounted. Apparently, I am not able to detect which network location is selected (or which IP I have) via AppleScript, so I need two different versions of the script at the moment.

I define the network shares, the servers, and the protocols, and with a double-click, I get all shares mounted. If any share was already mounted, the script assumes that it has to disconnect every defined share. Works with FTP, NFS and SMB shares; perhaps even with more.

[robg adds: I haven't tested this one...]
    •    
  • Currently 2.80 / 5
  You rated: 2 / 5 (5 votes cast)
 
[17,022 views]  

Mount and unmount server shares via AppleScript | 5 comments | Create New Account
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: fresler on Mar 21, '05 11:25:19AM

You can see if you're on a particular network via IP like this:
set zippy to do shell script "ping -c 1 192.168.1.93"
if zippy contains "1 packets received" then
...
end if



[ Reply to This | # ]
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 | # ]

Mount and unmount server shares via AppleScript
Authored by: rhix on Mar 21, '05 12:30:36PM

I hate to sound like I'm plugging my own software here... but by the looks of it you could make good use of a program I started writing. It allows you to set a bunch of options according to which network location you're in, including mounts (though it doesn't unmount anything yet). The mounting part of it needs reworking (badly), when I get more free time I'll work on that. This is the first time I ever put it out publicly, it doesn't have a page for it yet, but I figure, if someone could make good use of it, cool.

http://www.centrix.ca/networklocation/NetworkLocation v0.32.zip

If you'd like to give me input about it, feel free to email me at rick(at)centrix(dot)ca. Also, I use applescript to do the location detecting/setting, I can give those out too.



[ Reply to This | # ]