Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

the Western zoo

macrumors 6502
Original poster
May 16, 2006
379
3
Aarhus C, Denmark
I know very little about coding, and next to nothing about using automator, so I am a little wary about just trying stuff on my own...

I would like to make a service that will run a Terminal command to reboot Core Audio - sometimes Airplay messes up audio. I have found the Terminal command by Googling, and also I have an idea about how I should set it up in Automator, but I would like to get some input from people in the know.

From what I have gathered, I should start a new service in Automator, choose run shell command, and paste the following:

sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`

I do not understand that command, but have found it by googling... If someone could explain what the individual parts mean I would appreciate it.

Usually when I run this command in terminal I have to input my password afterward, is there a way around this when setting up this service?
 
Code:
sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`

I do not understand that command, but have found it by googling... If someone could explain what the individual parts mean I would appreciate it.


Each program running on the system has a process id, the kill command expects a process id (pid for short) as an argument.

Above, "kill" is followed by a whole string of commands that are surrounded by back tick quotes ` what these do, is to replace the quoted part with it's result, which in this case is the pid. (the purpose of this is to find the pid for the process named 'coraudiod').

You can test that by running it in isolation. ps -ax lists running processes, this is then piped to a grep filter which only shows rows with 'coreaudiod'. A second filter is then used because grep itself will show up. The reason for this is that the argument to grep is 'coreaudiod'. And finally, only the first column is printed by specifying $1 in awk.

All of this is unnecessary though, because there is a "killall" command that takes the process name as argument as opposed to the pid, so it can be replaced by:

Code:
sudo killall coreaudiod


Usually when I run this command in terminal I have to input my password afterward, is there a way around this when setting up this service?

'coreaudiod' is owned by root, so you need to be super user to kill it.


There may be better ways to fix the Airplay issue than killing the system wide audio daemon.
 
Last edited:
How did you create in automator

Can you please explaing the process for creating this service in automator? Thanks for taking the time.
 
Can you please explaing the process for creating this service in automator? Thanks for taking the time.


Screenshot_12_08_2014_05_32.png


launch automator, choose service from the options

tester_workflow.png


select 'utilities'

drag 'run applescript' into the main window

set 'service receives' to 'no input'

in the run applescript dialog enter the following text:

Code:
on run
	
	do shell script "sudo killall coreaudiod" user name "John Doe" password "abcd" with administrator privileges
	
end run

replace John Doe with user account name and replace abcd with the users password

alternately you could use

Code:
on run
	
	do shell script "sudo killall coreaudiod" with administrator privileges
	
end run
though in that case you'll be prompted for password every time you call the service
 
Thank you so much for taking the time.

Image

launch automator, choose service from the options

Image

select 'utilities'

drag 'run applescript' into the main window

set 'service receives' to 'no input'

in the run applescript dialog enter the following text:

Code:
on run
	
	do shell script "sudo killall coreaudiod" user name "John Doe" password "abcd" with administrator privileges
	
end run

replace John Doe with user account name and replace abcd with the users password

alternately you could use

Code:
on run
	
	do shell script "sudo killall coreaudiod" with administrator privileges
	
end run
though in that case you'll be prompted for password every time you call the service
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.