VLC 2.2.5.1 isn't quitting using our script that works for older versions

donmontalvo
Esteemed Contributor III

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?

--
https://donmontalvo.com
6 REPLIES 6

ryan_ball
Valued Contributor

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.

donmontalvo
Esteemed Contributor III

@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
--
https://donmontalvo.com

tlarkin
Honored Contributor

Maybe try using bundle ID to quit the app?

tlarkin
Honored Contributor

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)

donmontalvo
Esteemed Contributor III

@tlarkin wow, nice...works if invoked as current user!

--
https://donmontalvo.com

tlarkin
Honored Contributor

Yup, this is why the Objective C bridge in Python is very powerful