• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Send Terminal window crtl-c
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Send Terminal window crtl-c


  • Subject: Re: Send Terminal window crtl-c
  • From: "Steven D. Majewski" <email@hidden>
  • Date: Mon, 4 Sep 2006 10:57:12 -0400


On Sep 4, 2006, at 9:51 AM, Gnarlodious wrote:

How would one send an open Terminal window a ctrl-c to stop a process?

For example:

tell application "Terminal"
	do script "top" in front window
	delay 10
	do script "^c" in front window
end tell

In this example, the ctrl-c doesn't quit the top window.


Control-C isn't a shell command, so "do script" won't work.
( And "^c" probably isn't the control-c character -- unless that representation
was an artifact of cutting and pasting into mail. You may be just sending the
character "^" followed by the character "c" )


And if you do send another script to that terminal, it would have to wait until
the "top" command finished running before it could run in that terminal shell.


Control-C and some other control characters are intercepted by the terminal driver
which in turn sends signals to the shell that owns that terminal. What characters
do what are conventional and can be mapped to different characters or turned
off. ( see 'man stty' ) Sometimes you don't want a user to be able to kill and escape
from a captive shell, for example.


The shell program to send signals to another process is 'kill' ( see 'man kill' )
The default signal sent is the signal to kill another process, but other signals can
be specified on the command line. ( type 'kill -l' for a list ). Control-C sends the
SIGINT or Interrupt signal, which usually attempts to do a proper cleanup and exit
of the process rather than an immediate forced exit. ( Other signals signal stop (SIGSTOP)
and continue (SIGCONT) for shell job control, various i/o errors, and line hangup ( SIGHUP ).



So to simulate what the control-C does, you want to send the SIGINT signal to the 'top' process.


Something like the shell command:
	kill -INT $(ps -aux | grep top | grep -v grep | awk '{ print $2 }' )
should do the trick.

'killall' is easier and avoids the grep and awk commands to find the process pid, but
top seems to be suid and runs as root, so killall didn't work for me ( and I'm not sure
I want to try to use killall on root. )


But, again, you can't try to run it in the terminal that is already running 'top',
so a "do shell script" would be better.



Maybe someone else will chime in if there's a better way to control processes from
System Events in Applescript rather than using kill & ps in the shell.


-- Steve Majewski






_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Send Terminal window crtl-c (From: Gnarlodious <email@hidden>)

  • Prev by Date: Send Terminal window crtl-c
  • Next by Date: Re: Send Terminal window crtl-c
  • Previous by thread: Send Terminal window crtl-c
  • Next by thread: Re: Send Terminal window crtl-c
  • Index(es):
    • Date
    • Thread