PDA

View Full Version : Applescript to connect to AFP or FTP server




arkestra
Jun 10, 2012, 04:38 PM
Hello,

I'm trying to write an applescript to connect automatically to my NAS over AFP on my local network, or over FTP if I'm outside.

I'm a beginner with Applescript, and I tried that:

tell application "Finder"
try
mount volume "afp://XXX:XXX@192.168.X.X/VOLUME"
end try
else
mount volume "ftp://XXX:XXX@xxxx.dscloud.me/VOLUME"
end tell

I would like the script to check connection with AFP, and if the connection cannot be set, to try a connection with FTP. And if it cannot connect, to do nothing (not even an error message).

Is it possible?

Thank you,

Mathieu



kryten2
Jun 10, 2012, 06:52 PM
There's no way around the error you get when any of the mount volume commands fail.

malokata
Aug 15, 2012, 11:48 AM
if (do shell script "ping -c1 000.000.0.000") contains "1 packets received" then
try
if (list disks) does not contain "SHARE" then
mount volume "afp://000.000.0.000/SHARE"
end if
end try
end if
on quit
continue quit
end quit

Replace 0's with your server IP, and SHARE with your share name.

fubaar
Sep 30, 2012, 05:01 PM
if (do shell script "ping -c1 000.000.0.000") contains "1 packets received" then
try
if (list disks) does not contain "SHARE" then
mount volume "afp://000.000.0.000/SHARE"
end if
end try
end if
on quit
continue quit
end quit

Replace 0's with your server IP, and SHARE with your share name.

this works but how do I make it reloop all the time?
when the connection to a share is broken i would like to reconnect.
Doesn't it have to reloop this script with an interval of say 10 seconds?