Quitting an OSX application remotely via ssh

So I use my laptop as an alarm clock: on waking from its sleep at a predetermined time it runs an applescript (to open Safari and EyeTV with Radio 4 selected) to hopefully wake me from mine. Sometime this script runs, I forget to quit EyeTV, and R4 is playing all day…

To resolve this you can run an applescript via the command line to quit any named application remotely, after logging in via SSH. The function below can be added to your .profile on the remote machine and used to quit any application you know the name of.

function remotequit {                                                          
if [ $# -eq 0 ]                                                                
    then                                                                        
    printf "%s\n" "Usage: remotequit application"                              
    else                                                                        
    osascript -e 'tell app "'${1}'" to quit'                                    
fi                                                                              
}

Info partly gleaned from here.