You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Killing AppleVNCServer with an applescript

Hi, I have a mac at home that I regularly access with VNC from work. AppleVNCServer has a habit of hanging every few days in between sessions. Sometimes if I'm lucky I can get in with logmein and kill the process, but logmein is really flaky from my connection at work for some reason so I can't rely on it. I want to set up a folder within Dropbox using folder actions that will run a script when I drop a file in it. I then want that script to kill the AppleVNCServer process.

I found this ( http://macstuff.beachdogs.org/blog/?p=31) which looks like it should pretty much do what I want. I changed "Finder" in his example to "AppleVNCServer". It seems to identify the process ID (209), but won't kill it. I get the following message:
error "sh: line 0: kill: 65
209: arguments must be process or job IDs" number 1

This is the script:

set app_name to "AppleVNCServer"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)

Does anyone see what's wrong here? I'm only just getting into Applescript. The shell script part is a little over my head...

Thanks,
Sean

G4 Mac Mini, Mac OS X (10.5.8)

Posted on Jan 22, 2010 1:20 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 22, 2010 1:33 PM

I don't understand why you need to do it that way.
just do

try
do shell script "killall AppleVNCServer"
end try
19 replies

Jan 22, 2010 2:16 PM in response to Sean C. Carter

Sean C. Carter wrote:
Oh you know what, I'm trying this on my 10.6 mac at the moment (my 10.5 mini that I hope to implement this on is already locked up for the day), does that make a difference?

no, it doesn't make a difference. but I don't understand. if you don't use ssh how were you planning to run those commands on the remote mac anyway? I'm really confused. as I understand it you problem is that you vnc into a remote mac and the vnc server on that remote mac hangs. then you need to access that mac remotely and kill the vnc server process. the only way I see how to do that is via ssh.

sshing is easy. just enable remote login on thaat remote mac in system preferences sharing. then on your mac open terminal and enter

ssh unsername@ip.address

where username is your user name on the remote mac and ip.address is the ip address of the remote mac.

Jan 22, 2010 2:21 PM in response to V.K.

I figured I'd have an applescript that could be triggered by a folder action. I use Dropbox (the app) and I could just drop a text file (or anything really) into the specified folder and it would sync over and cause the applescript to run.

Maybe that's a little over complicated, but it made sense to me...

Also I use windows XP at work, so I don't have terminal, unless the command prompt can be used om a similar way?

Jan 24, 2010 5:00 PM in response to V.K.

Hi VK,

So I've enabled SSH on my Mini and I've successfully logged into it from another location (using my MacBook for now). I screenshare to it, and at the same time open terminal on my MacBook:


Last login: Thu Jan 21 20:33:14 on console
MacBook:~ ltcarter47$ ssh ltcarter47@xx.xx.xx.xxx
The authenticity of host 'xx.xx.xx.xxx (xx.xx.xx.xxx)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xx.xx.xx.xxx' (RSA) to the list of known hosts.
Password:
Last login: Mon Mar 23 14:49:00 2009
PPC-Mac-Mini:~ ltcarter47$ killall AppleVNCServer
No matching processes belonging to you were found


I'm baffled... Seems like that should do the trick right?

Jan 24, 2010 5:29 PM in response to V.K.


PPC-Mac-Mini:~ ltcarter47$ ps aux |grep AppleVNC
ltcarter47 112 12.0 1.7 153180 17640 ?? S 5:02PM 3:36.42 /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/MacOS/AppleVNCServer
root 31 0.0 0.1 76368 1064 ?? Ss 5:01PM 0:00.08 /System/Library/CoreServices/RemoteManagement/AppleVNCServer.bundle/Contents/Support/RFBRegisterMDNS
PPC-Mac-Mini:~ ltcarter47$

Killing AppleVNCServer with an applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.