Your best friend for file transfer.

Fetch application logoFetch

Non-blocking AppleScript (5 posts)

  • Started 14 years ago by Lee
  • Latest reply 14 years ago from Scott McGuire
  • Lee Member

    I have this script:

    tell application "Fetch"
    set theFile to alias "Macintosh HD:Users:leehinde:Documents:Clients:username:Final Application.dmg"

    activate
    make new transfer window at beginning with properties {hostname:"Host1", username:"username", password:"1111", initial folder:"Desktop/", authentication:SFTP, encrypt:true}

    make new transfer window at beginning with properties {hostname:"Host2", username:"username", password:"1111", initial folder:"Desktop/", authentication:SFTP, encrypt:true}

    make new transfer window at beginning with properties {hostname:"Host3", username:"username", password:"1111", initial folder:"Desktop/", authentication:SFTP, encrypt:true}

    with timeout of (60 * 15) seconds
    put into transfer window "Host1" item theFile
    end timeout

    with timeout of (60 * 15) seconds
    put into transfer window "Host2" item theFile
    end timeout

    with timeout of (60 * 15) seconds
    put into transfer window "Host3" item theFile
    end timeout

    end tell

    The goal is to upload the same file to three different servers. The issue (and it's minor) is that the way the script runs, the 2nd upload doesn't start until the first one is finished, and the third doesn't start until the 2nd one is finished.

    If I was doing this manually I could upload to all three servers concurrently.

    Is there a way to structure the script so it does that?

    Posted 14 years ago #

  • Scott McGuire Administrator

    Hi Lee,

    Yes, there is a way to change the script so that all the uploads run concurrently.

    Add "with immediate return" to the end of each of the "put into" lines, so that you have:

    put into transfer window "Host1" item theFile with immediate return

    The "with immediate return" property (which only applies to "put into" or "open") tells Fetch and the script to not wait to see the result of the upload before moving on to the next line of the script.

    Please let us know if that doesn't do what you want or if you have further questions.

    Thanks,

    Scott McGuire
    Fetch Softworks

    Posted 14 years ago #

  • Scott McGuire Administrator

    Hi again Lee,

    A co-worker pointed out to me that another, more general way to accomplish what you want is to put the commands you want to run concurrently in an "ignoring application responses" block. This tells AppleScript not to wait for results from any commands inside the block.

    Since this is an AppleScript feature, not a special Fetch property, it can be applied to any AppleScript command, as opposed to "with immediate return" which only applies to a select few Fetch commands. ("with immediate return" has the advantage of returning an object that you can examine to find out how the transfer is progressing, whereas "ignoring application responses" means you don't get any returned objects, but I expect that isn't important to you.)

    So you could also do the following:

    ignoring application responses

    with timeout of (60 * 15) seconds
    put into transfer window "Host1" item theFile
    end timeout

    with timeout of (60 * 15) seconds
    put into transfer window "Host2" item theFile
    end timeout

    with timeout of (60 * 15) seconds
    put into transfer window "Host3" item theFile
    end timeout

    end ignoring

    Either approach should do what you want.

    Best,

    Scott McGuire
    Fetch Softworks

    Posted 14 years ago #

  • Lee Member

    Thanks Scott; I appreciate it.

    Posted 14 years ago #

  • Scott McGuire Administrator

    Hi Lee,

    You're welcome.

    Just one further point of clarification - the "with timeout" blocks actually aren't necessary inside an "ignoring application responses" block; I should have been more careful when cutting and pasting. Since AppleScript has been told to not wait for responses, there is no chance of commands timing out.

    Similarly, "with timeout" isn't necessary if you use the Fetch "with immediate return" property.

    (It won't hurt to include the "with timeout" blocks, but they aren't doing anything useful, either.)

    Best,

    Scott McGuire
    Fetch Softworks

    Edited 14 years ago #

Reply

  • Or nickname, if you prefer.
  • This will be kept confidential.
  • This is to ensure that you’re a person, not a spambot.