Macro to Kill a Specific Process (coreaudiod) – Cant Find It in Quit App

Hi all

im looking for a way to to kill a specific process (coreaudiod), buit cant find it in quit app applications presented. any clue how to quit it via KM?

thx

Z

Keyboard Maestro only offers to quit foreground applications (since they are quit via AppleEvents).

coreaudiod is a background only application.

You can probably use the shell command killall to kill it.

But since the process is not owned by you, you need

sudo killall coreaudio

And since you don't want to type your password in each time, you need to add the following line to your /etc/sudoers file:

username ALL= NOPASSWD: /usr/bin/killall coreaudiod, !/usr/bin/killall coreaudiod *

(replace “username” with your username on your Mac).

And you should not do any of this without understanding what sudo, sudoers and killall do, as this is all low level stuff that is somewhat dangerous and/or security risks.

2 Likes

Hello! I have a similar question. I need to be able to kill a process called "Daylite Helper" without killing the process called Daylite. When I do killall "Daylite Helper" it kills Daylite too. I've tried the following and it just kills Daylite and Daylite helper

set app_name to "Daylite Helper"
do shell script "killall " & app_name

I've also tried the one below, but it cannot find that process.

do shell script "killall " & quoted form of "Daylite Helper"

Any ideas?

Have you tried killing the "Daylite Helper" process using the macOS Activity Monitor?
I suspect that it will also result in killing "Daylite". If so, then you can't use "killall".

Why do you want to kill "Daylite Helper"?

Based on this support article:
Sync Failed - Could not connect to Daylite Helper

It appears that it is needed to do Daylite sync, which you can turn off:

  1. Open Daylite
  2. From the menu bar choose Daylite > Preferences and click General
  3. Unselect the checkbox labelled "Sync in the background"
  4. Quit Daylite

I can kill the Daylite Helper process using Activity Monitor, and the Daylite app does not quit when doing so. This is the process that I am trying to automate with KM.

There's a bug in the app that causes Daylite Helper to stop syncing. The only solution that I have found (other than working with Marketcircle to address the bug, which I am also working on), is to kill the Daylite Helper process. Doing so immediately restarts it, and sync starts working as expected.

OK, that's good to know.
Does it work properly if you manually enter the command in Terminal?

I suspect a problem with properly quoting "Daylite Helper" so that it is the target and NOT just "Daylite".

But i'm a Bash neophyte. If no one here can provide the answer, you might try posting on the stackoverflow.com board.

No - it kills Daylite too. I agree about the properly quoting. One way to do it would be to look up the PID for Daylite Helper and then to kill it by PID, but I couldn't figure out working code for that despite much googling.

I seem to have figured it out! In case anyone needs it:

tell application "System Events"
   set ThePID to the unix id of (every process whose name contains "Daylite Helper") as text
   do shell script "kill -KILL " & ThePID
end tell
1 Like

For reference in future posts, it is best to post scripts/code in a Code Block.

Hi @egordin, sorry I’m a bit late with my contribution and I’m glad you figured out a solution. In case this still might be useful, I wrote this script to kill foreground and background processes by choosing from a list:

#!/usr/bin/osascript
--------------------------------------------------------------------------------
# pnam: TERMINATE PROCESSES
# nmxt: .applescript
# pDSC: Presents a list of running processes for termination
 
# plst: -
 
# rslt: - Processes terminate
--------------------------------------------------------------------------------
# sown: CK
# ascd: 2018-09-17
# asmo: 2019-05-12
--------------------------------------------------------------------------------
use framework "Foundation"
use scripting additions
 
property this : a reference to the current application
property NSPredicate : a reference to NSPredicate of this
property NSSortDescriptor : a reference to NSSortDescriptor of this
property NSWorkspace : a reference to NSWorkspace of this
 
property Workspace : a reference to NSWorkspace's sharedWorkspace
 
property key : "localizedName"
--------------------------------------------------------------------------------
# IMPLEMENTATION:
set A to Workspace()'s runningApplications()'s sortedArrayUsingDescriptors:[¬
	NSSortDescriptor's sortDescriptorWithKey:key ascending:yes ¬
	selector:"caseInsensitiveCompare:"]
 
tell {} & (choose from list A's localizedName as list ¬
	with title ["Running Processes"] ¬
	with prompt ["Select processes to kill:"] OK button name ["Quit"] ¬
	with multiple selections allowed without empty selection allowed) ¬
	to set procs to A's filteredArrayUsingPredicate:(NSPredicate's ¬
	predicateWithFormat_(my key & " IN %@", it))
 
repeat with proc in procs
	# proc's terminate()
	proc's forceTerminate()
end repeat
---------------------------------------------------------------------------❮END❯

Terminate Processes.applescript

1 Like

Thank you @CJK! I wish I knew what any of that code does, but I really appreciate you getting back to me about it!

Hey Eugene,

@CJK's code pops up a list of user processes and allows you to pick one or more of them to quit.

Another option is to use the pkill shell command in an Execute a Shell Script action:

pkill -ix 'Daylite Helper'

-Chris

@egordin, adding to what @ccstone said, I would say that, for me, that script is one I use only when I have tried to gracefully quit an application that has frozen (which often still responds to an AppleScript quit command). But I get more use out of it simply to see a fairly comprehensive list of running processes, and to inspect for any lurkers when my system seems to slow and I think I know which processes are responsible.

It was a re-write of the original script where I used kill (before I knew pkill existed). This one is a lot easier to read and understand:

set my text item delimiters to linefeed
tell application "System Events" to set P to the name of every process as text

set my text item delimiters to space
set sh to the contents of {¬
	"printf", quoted form of P, ¬
	"|", "sort -u"} as text
do shell script sh

set ProcessList to paragraphs of the result

set PIDs to {}

repeat with P in (choose from list ProcessList ¬
	with title ("Running Processes") ¬
	with prompt ("Select processes to kill:") ¬
	OK button name ("Quit") ¬
	multiple selections allowed true ¬
	without empty selection allowed)
	
	tell application "System Events" to set the end of ¬
		PIDs to the unix id of the process named P
	
end repeat

if PIDs = {} then return

set my text item delimiters to space
set sh to {"kill -s ABRT", PIDs} as text
do shell script sh

Thank you all! One other related question for you. I'd like to have KM check if the Daylite Helper has essentially stopped working, and then kill it if so. The way I would do this is to check the Daylite File menu item, which lists how long it has been since Daylite has synced. If the duration is more than, say 30 minutes, then KM would kill Daylite Helper, and it would sync. Does anyone know how to get and parse this "time-since-sync" information and parse it? I could have a regularly timed KM macro run and check. Here's what the menu looks like for reference.