Force quit Terminal.app using Apple Script Editor

5,275

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
Share:
5,275

Related videos on Youtube

code-8
Author by

code-8

Updated on September 18, 2022

Comments

  • code-8
    code-8 almost 2 years

    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 ?

  • user3439894
    user3439894 over 3 years
    A simple do shell script "pkill -9 -x Terminal" will do the job without then need for System Events.
  • CJK
    CJK over 3 years
    @user3439894 Ugh, there are a few small but irksome niggles in this answer that I kind of find embarrassing to be reading two years later, wondering why the hell did I used to indent code blocks from line 1. I'm also appalled I headed straight for SIGKILL, which is kinda overdoing it and not recommended to be sent by the user. Most force quits are SIGTERM. But I must not have known about pkill back then, as I never use kill now as pkill makes it easier, and also has more functionality along with pgrep. So, what drew you back here, then? Were you trying to quit Terminal?
  • user3439894
    user3439894 over 3 years
    CJK, It got bumped to the top of the cue by Community, so I took a look at it, that's all. :)
  • CJK
    CJK over 3 years
    @user3439894 Ah, ok. Thanks for telling me. In that case, I shall update the answer as there's enough bad AppleScript and Shell Script examples out there, I should do my best not to add to that if it's possibly getting a wider/renewed exposure.