-1

To end a screen process you should type this:

ctrl-a
ctrl-\
y

But how to send a ctrl command to terminal using an apple script?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tym3k
  • 45
  • 2
  • 7
  • This is actually a potentially useful question (and I uprooted it); but did you know you can run scripts from *within* Terminal, instead of trying to script Terminal.app? – Michael Dautermann Dec 20 '14 at 15:16
  • Yes I know, but I'm making an app with a gui for communicating with a serial device and I want to create a 'disconnect' button. – Tym3k Dec 20 '14 at 15:18

1 Answers1

0

This should do the trick:

do shell script "{ killall SCREEN; killall screen; :; } &> /dev/null"

Note this will kill all instances of screen, in case there is more than one running.

I don't know if it's overkill to do it this way, but I have sometimes seen the all-caps process appear when I use screen, so this just makes sure that all bases are covered. The colon means "do nothing" and since it always returns error code 0 (meaning no error), it prevents AppleScript potentially complaining about an error in case screen isn't running (otherwise, you'd have to wrap the command in a try...end try). Same goes for the redirection to /dev/null so you don't hear about an error that doesn't matter.

You could also simulate the keystrokes themselves using GUI Scripting (see http://www.macosxautomation.com/applescript/uiscripting/). This is more work and less reliable, so I'd just do the above.

Ivan X
  • 2,165
  • 16
  • 25