title: Applescript to ping test each client prior to ssh connection
body: <p>I'm trying to make an Applescript that connects to a list local ssh machines, with each connection opening in a new terminal window. Prior to attempting the ssh connection, I'd like to ping the client to see if it's available: if it is, run the ssh command, if not then iterates to the next client. When I run the script it seems to work for the first connection but then gives me <code>--&gt; error number -10004</code> for the remaining clients (and hangs the debugger). Any feedback would be greatly appreciated, thanks!</p>
  
  <pre><code>set hosts to {"10.2.0.199", "10.2.0.11", "10.2.0.91", "10.2.1.591", "10.2.0.41"}
  set uname to {"asus_client01", "asrock_comp", "msi003", "gigabyte4", "intel05client"}
  tell application "Terminal"
      activate
      repeat with i from 1 to the count of hosts
          set this_uname to item i of uname --extract individual username
          set this_host to item i of hosts as string --extract iPv4 
          set uname_host to this_uname &amp; "@" &amp; this_host
          set hostUp to true
  
          try
              do shell script "ping -c 1 -t 5 " &amp; this_host
          on error
              set hostUp to false
              display dialog this_host &amp; " seems to be down."
              delay 2
          end try
  
          if hostUp then
              do shell script "ssh " &amp; uname_host
          end if
      end repeat
  end tell
  </code></pre>