MacOS – How to quit “Force Quit Applications” using AppleScript

applescriptmacos

I've been learning lots of different programming languages when I came across AppleScript. Since I'm technically new to it, this question may seem dumb.

I need an AppleScript script to quit the "Force Quit Applications" app.

The following code doesn't work:

tell application "Force Quit Applications" to quit

Probably it's because the process has a different name. What is the "Force Quit Applications" process name? Many thanks in advance.

Best Answer

You can use this Apple Script to close this window:

tell application "System Events"
    key code 53 using {command down, option down} -- ESC + ALT + CMD
    keystroke "w" using command down
end tell

This window is owned by loginwindow process and it's not that easy to interact with it. Here's the code to press Force Quit button on this window:

tell application "System Events" to tell process "loginwindow"
    click button 1 of window 1 
end tell

However this does not work:

tell application "System Events" to tell process "loginwindow"
    close window 1
end tell