Glam Prestige Journal

Bright entertainment trends with youth appeal.

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 ?

2 Answers

It looks like I found the answer to my owned question

tell application "Terminal" quit tell application "System Events" keystroke return end tell
end tell

Sending a 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"
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy