Posted on 06-27-2019 09:40 AM
We've been using @mm2270's script for quite some time, it works great.
But for some reason won't quit VLC 2.2.5.1 (quits older versions without a problem).
Here is the script, the process name is VLC
as per Activity Monitor:
#!/bin/bash
# Kudos to @2270 on Jamf Nation.
# EXACT process name (if multiple, carriage return between each)
PROCESSES=("VLC")
# Exact application path.
APPLICATION=""
# Do not edit between these two lines ---------------------------------------------------
for PROC in "${PROCESSES[@]}"; do
RUNNING_PROCESSES=$(ps axc | grep -i "$PROC" | awk '{print $1}')
if [[ $RUNNING_PROCESSES ]]; then
echo "Found running process $PROC with PID: ${RUNNING_PROCESSES}. Killing it..."
kill $RUNNING_PROCESSES
else
echo "$PROC not found running..."
fi
done
# Do not edit between these two lines ---------------------------------------------------
# Remove application
# /bin/rm -rf "$APPLICATION" 2> /dev/null
exit 0
Any ideas?
Posted on 06-27-2019 09:45 AM
First try a ps -ax | grep -i vlc
to get the name of the process.
Not at my Mac right now to see the process name.
Posted on 06-27-2019 10:05 AM
@ryan.ball thanks, yes it does find the PID (confirmed in Activity Monitor):
$ ps -ax | grep -i vlc | grep -v grep
81407 ?? 0:01.21 /Applications/VLC.app/Contents/MacOS/VLC
Posted on 06-27-2019 11:13 AM
Maybe try using bundle ID to quit the app?
Posted on 06-27-2019 11:25 AM
PIDs can get messy, especially with sand boxing, I have swapped all app quitting to use Bundle IDs
#!/usr/bin/python
from Cocoa import NSRunningApplication
BID = "org.videolan.vlc"
def quit_app(bid):
apps = NSRunningApplication.runningApplicationsWithBundleIdentifier_(bid)
if apps:
for app in apps:
app.terminate()
quit_app(BID)
Posted on 06-27-2019 11:35 AM
@tlarkin wow, nice...works if invoked as current user!
Posted on 06-27-2019 01:44 PM
Yup, this is why the Objective C bridge in Python is very powerful