Applescript to connect to AFP or FTP server

Discussion in 'Mac Programming' started by arkestra, Jun 10, 2012.

  1. macrumors newbie

    Jun 10, 2012

    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"
    mount volume "afp://XXX:XXX@192.168.X.X/VOLUME"
    end try
    mount 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,

  2. macrumors 6502a

    Mar 17, 2012
    There's no way around the error you get when any of the mount volume commands fail.
  3. malokata, Aug 15, 2012
    Last edited by a moderator: Aug 15, 2012

    macrumors newbie

    Aug 15, 2012
    Try this

    if (do shell script "ping -c1") contains "1 packets received" then
    		if (list disks) does not contain "SHARE" then
    			mount volume "afp://"
    		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.
  4. macrumors newbie

    Sep 30, 2012
    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?

Share This Page