Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mixvio

macrumors 6502
Original poster
Apr 12, 2009
388
0
Sydney, Australia
First off apologies if this is in the wrong place, I wasn't sure if Applescript requests belong here or under the Programming forum.

I have a Time Capsule which has an external USB drive connected to it and made available over the network. What I'd like to do is set up a script that automatically mounts that share whenever I boot or wake from sleep, or fail silently if the drive isn't available (IE, because I'm not at home or what).

I've got everything working except for the "fail silently" part. The script runs appropriately at login and when waking from sleep, provided that I'm on my home network. When I'm not, I get an error and it all seems to go kinda crazy.

The script in question is here:

Code:
delay 10

property DRIVENAME : "afp://Time Capsule._afpovertcp._tcp.local/DRIVENAME/"
mount volume ARCHON

I was trying to figure out if there are conditionals, if/then etc, but I can't seem to work out how to get it to first check for the existence of the Time Capsule before trying to mount the share. My MacBook is connected over LAN at home, not wifi, so I don't know if searching for the network SSID will work as Airport is off when I'm at my desk.

Alternatively if there's just a simple way to have it fail gracefully if the share isn't found that would be excellent too.

Any suggestions?
 
Since this got no replies, in case anyone is searching for something similar I managed to get it working using a version of this script from zachmb:

Code:
delay 10

-- Check IP address is reachable

set IP_address to "192.168.0.xxx" (note, I have a non-standard IP set for my router which was how this worked)

set IP_Valid to true

try
	do shell script ("ping -c 2 " & IP_address)
on error
	set IP_Valid to false
end try

-- PREP SSID DETECTION

set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"



-- IF NETWORK IS HOME

if SSID is "AIRPORTTIMECAPSULE" or IP_Valid then
	
	-- MOUNT DRIVE
	
	mount volume "afp://AIRPORTTIMECAPSULE._afpovertcp._tcp.local/EXTERNALDRIVE/"
	
	-- SET RESULT VAR TO "WIN"
	
	set endresult to "win"
	
	-- ELSE
	
else
	
	-- DO NOTHING
	
	-- SET RESULT VAR TO "FAIL"
	
	set endresult to "fail"
	
	-- END
	
end if

I cut out the Growl stuff since I don't need it sending me notifications. Change the drive and Airport name accordingly for your own needs. This works for me and properly mounts the drive if I'm on home wifi or ethernet, and silently fails if it can't be found.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.