Applescript to connect to AFP or FTP server

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

  1. macrumors newbie

    Joined:
    Jun 10, 2012
    #1
    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
     
  2. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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

    Joined:
    Aug 15, 2012
    #3
    Try this

    Code:
    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.
     
  4. macrumors newbie

    Joined:
    Sep 30, 2012
    #4
    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