MacOS: how to close an application using a command line?


Image: June Wan/ZDNET.

If you work on macOS, you know that applications rarely behave in unusual ways. Despite everything, it happens sometimes. So, when an application no longer responds, the interface has provided a tool to help you close it: just go to the Apple menu, then Applicationsselect the application in question and click on Force quit.

However, it is not always possible to use this menu. And when force stopping a forced application doesn’t work, we usually turn to restarting the Mac. However, this is not the only solution. In fact, there is even a better solution, which uses the power of command lines. Yes, like on Linux! With this power, you will be able to control all applications, and make them do what you want – including closing them when they refuse to work properly.

You will therefore learn two command lines, thanks to which no application will resist you when you ask it to close. This trick works on all Macs, regardless of the version of macOS you are using. However, it is always recommended to update your OS to benefit from the latest security patches, in particular.

1. Open the terminal

To get started, open the app Terminal by clicking on the corresponding icon in the Launchpad.

2. Locate the app to close

Here’s the tricky part: you have to find the name of the application to close.

In the following example, we will take Apple’s messaging application, Mail. Remember: Linux commands are case sensitive. So, we are not looking for “mail” (e-mail, mail), but “Mail” (the name of the application).

So we are going to use two Linux commands, p.s. And grep, to list all applications containing the word “Mail” that are currently running. For this task, the command to enter is as follows:

ps aux |grep Mail

If you want to know what this command line means, here’s how it breaks down:

  • The command p.s. displays current processes;
  • to added to order p.s. to display all processes associated with a user ID;
  • | is a pipe that sends the output of the first command to the next command;
  • The command grep searches for a character string (pattern) in a specific file;
  • Email is the pattern selected for the order grep.

The command line should look something like this:

jackwallen 20722 0.0 2.3 415470192 378896 ?? S Thur09PM 21:07.22 /System/Applications/Mail.app/Contents/MacOS/Mail

Thanks to this list, we now know that the application is in fact running under the name Email. We can therefore use this name to force the application to stop.

This check is necessary, not only to be sure to be able to exit the application, but also and above all to be sure not to close another application, which could have a similar name, but be essential for our use.

2. Close the app

To force the application to stop, the easiest way is to use the command killall.

In the previous example, the command line to close the Mail application is as follows:

killall Mail

You can check: the Mail application is closed! And this, even if the menu Force quit did not work.

Warning !

Use this procedure only when the menu Force quit does not work, and if you are sure you know the name of the application you want to close.

Above all, do not use the command killall randomly: you could cause damage to your operating system and/or lose data.

As Uncle Ben said to Spiderman, “with great power comes great responsibility”: this command can be of great help to you, but only if you use it wisely and sparingly.

Source: ZDNet.com



Source link -97