-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMac-Check-Prohibited-App-Running.sh
More file actions
40 lines (27 loc) · 1.1 KB
/
Mac-Check-Prohibited-App-Running.sh
File metadata and controls
40 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# This script is provided AS IS without warranty of any kind.
# https://github.com/Mac-Nerd/Mac-scripts
# -----------------------------------------------------------
# This script will attempt to determine if a particular app or process is running. If so,
# the script will exit in a failed state, so you can trigger a task to quit the process if needed.
AppToKill=$1
if [ -n "$AppToKill" ]
then
echo "[NOTICE] This script requires the name of an app or process."
exit 0 # exit quietly without triggering an alert.
fi
currentUser=$(stat -f "%S"u /dev/console)
currentUID=$(/usr/bin/id -u "$currentUser")
if [ "$currentUser" == "LoginWindow" ]
then
echo "[NOTICE] No logged in user."
exit 0 # exit quietly without triggering an alert.
else
# is the specified application or process running?
if [ $(pgrep -ilf "$AppToKill") ] || [ $(pgrep -ilf "$AppToKill".app) ]
then
echo "Found $AppToKill."
/bin/launchctl asuser "$currentUID" /usr/bin/osascript -e "tell application \"${AppToKill}\" to quit"
exit 1001 # exit and alert/fail. Trigger the "force quit prohibited app" task.
fi
fi