I'm trying to force quit my Terminal.app using Apple Script Editor
tell application "Terminal" quit end tell tell application "System Events" key code 53 end tell
It does not seem to work. How would one go about and did that ?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
quit command and a
keystroke doesn't equate to a force-quit. I assume that the solution you settled upon appeared to work simply because, after being issued a
quit command, I'm guessing a dialog box popped up asking whether you'd like to force-quit Terminal. Hitting Enter—either physically or programmatically—would then select the force-quit option presented to you.
The problem with sending a key press programmatically is that, if the focus unexpectedly changed to another window on your system, that key press would be sent to the wrong window.
One bonafide method of force-quitting an app from AppleScript is to obtain its PID, then issue a
kill command via a shell script. It's actually just a single line of code. Here's what it would look like when used to deal with your situation (formatted over two lines for readability):
tell application "System Events" to ¬ do shell script "kill -9 " & unix id of process "Terminal"