Category filter

Script to force close apps on Mac

When your app gets stuck on your Mac, you can force close the app and all its running processes with a single line of script from the Mac Terminal. This is an extremely useful command as it allows you to close the app without having to interact with the system GUI and also obtain diagnostic notes to assist in further troubleshooting.

Device admins can remotely run scripts on Macs managed with Hexnode using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Force close an app

Example – killall –v Notes

The killall command is used to kill all instances of a process running on your system by passing the name of the process. The command will terminate the process forcibly when the specified process name matches.

killall is a case-sensitive tool, so make sure that you enter the name correctly. For example, if you want to terminate an app named ‘Notes’:

#Wrong Command

#!/bin/bash

killall notes

#Right Command

#!/bin/bash

killall Notes

You may add the following options to the command –

-d

Returns detailed information about the running process, which includes number of processing units available to the process(nprocs), numeric code of the signal applied to the process(sig), process ID(pid), process name(cmd) and device specific information, without killing the process. This information could be used for verifying the correct process to be terminated while the process itself is not being terminated.

-v

Returns the unique PID (Process Identification Number) assigned to the running process after terminating it.

-l

Returns the list of all available signals which can be used with the killall command without terminating the running process. Signals are software interrupts that provide a way for the user (or a process) to communicate directly with a process, which in turn performs the task specified in that signal when used along with the killall command.

You can optionally add a signal to the killall command. For example:

killall –abrt Pages – Here, the signal ABRT forces the Pages app to quit abruptly with the problem report page opening simultaneously.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository