Running autossh with OSX automator

On my work OSX laptop I have a need to have some ports forwarded to my NAS at home, until now I’ve been manually running the ssh command (using a script) but this becomes very annoying when connections drop etc. In an effort to automate things, I wanted to run autossh automatically in the background.

I followed this guide and everything was working, however now I got stuck with a rotating wheel icon in the status area (near the clock). That became annoying quickly so I found this stackexchange answer to guide me in the right direction.

Instead of running the a shell script action in automator (as the initial guide suggested), I now have an apple script that executes autossh directly (and in the background). Here it is for completeness:

on run {input, parameters}
   ignoring application responses
      do shell script "/opt/local/bin/autossh -M 20000 [rest of ssh parameters] -N [hostname to connect to]& &>/dev/null"
   end ignoring
end run

This runs the script in the background, you can check with ‘ps’ if autossh is actually running. No more spinning wheel!