Help me kill this window

xrayspx's picture

I have a bash script on my work Mac which creates an ssh tunnel to my home machine, then runs the Mac VNC client so I can VNC home without opening VNC externally. All this works great with key based auth and stuff for the ssh session, so I just get a login prompt for the VNC session and I'm on my way.

At the end, I try to have it clean up after itself, I've tried using waits and then killing the PIDs associated with things like the tunnel, so when Screen Sharing closes, it tears down the SSH tunnel.

The one thing left is that it opens in a window, which it leaves behind at the end with a [process completed] message. I'd love to be able to kill that window, but I can't tell what PID is associated with that specific window, so I'm left with just closing it later. It's no big deal, but it's just an annoyance.

I have it killing the PID of the bash shell it's using, but the window itself remains...

#! /bin/bash

for pid in `ps -A | grep localhost\:5901 | grep my-home-machine | awk '{print $1}'`
echo $pid
kill $pid
ssh -c arcfour,blowfish-cbc -N -L 5903:localhost:5901 xrayspx@my-home-machine &

sshpid=`jobs -p`
echo $sshpid
shellpid=`echo $$`
echo $shellpid
sleep 5

/System/Library/CoreServices/Screen\\ Sharing /Users/xrayspx/Launchers/vnc--

#kill $sshpid
kill $shellpid

There is a setting in's preference to close windows when the shell exits cleanly, takes care of that. It's the next best thing to not having the terminal window open at all.

Thanks Matt!