How to force quit Applescript app from terminal?

The reason killall LightsOn doesn't work is because all running AppleScript application's process name is applet. For example, the executable path is:

../LightsOn.app/Contents/MacOS/applet

In general and assuming the process(es) is(are) not hung, one could use killall applet however that will terminate all running AppleScript applications, and of course that may not be desirable.

When a process is hung, you'll need to use a KILL signal, e.g.:

killall -KILL applet

However, pkill is the way to go to easily target a specific AppleScript application and because it's hung... use a KILL signal, e.g.:

pkill -9 -f LightsOn

Or:

pkill -KILL -f LightsOn

Note in this instance, -9 is just another way of saying -KILL.

Now with pkill and using the -f option, one can use more of the full argument list, e.g.:

pkill -9 -f /Applications/LightsOn.app/Contents/MacOS/applet

Then there's no ambiguity as to which applet process one is targeting. One can use as much of the full argument list as one feels is necessary to target the correct process.

For example, pkill -9 -f LightsOn will terminate an AppleScript application named NoLightsOn, so always use enough of the full argument list to terminate the correct process.


For reference:

From the pkill man page:

 -f          Match against full argument lists.  The default is to match
             against process names.

From the killall man page:

 Some of the more commonly used signals:

 1       HUP (hang up)
 2       INT (interrupt)
 3       QUIT (quit)
 6       ABRT (abort)
 9       KILL (non-catchable, non-ignorable kill)
 14      ALRM (alarm clock)
 15      TERM (software termination signal)

Note that this is just a partial signal list and is used with many of the different utilities that can terminate a process. See the various manual pages of the utilities used for additional information.


Try this:

ps auxwww | fgrep -v fgrep | fgrep -i LightsOn

That should show you the matching process information.

You can also try pkill which should work like this:

pgrep -fl LightsOn

If that shows you the PID, then you can move on to pkill:

pkill -9 -f LightsOn

When you run pkill -9, you're not telling the application to terminate itself, instead you're telling the OS to stop running the program, no matter what the program is doing.

When app gets stuck sending the kill without specifying the signal #, it will automatically assign to it the signal <15>, which means asking the app to terminate it self, it can not do that while stuck.