Skip to main content
Solved

AudioDevice not scriptable?


Forum|alt.badge.img+13

Good morning all,
Has anyone able to script AudioDevice? I have a simple script to change the input and output source using "Audiodevice".

#!/bin/sh

#  Outputspeaker.sh
#

/usr/local/bin/audiodevice output "WavTap"

In Terminal, it works without a problem, but when scripting, it just ignores it. I've tested on 10.7 and 10.9

Thanks in advance!

Best answer by mikeh

I have scripted it successfully. It took a while to figure out what was going on.

I'm guessing that the problem you're encountering is that the script doesn't seem to do anything when run by Casper? The audio input/output options are user-level options, not system-level options. When Casper runs the script, it does so as "root", so it simply sets the audio options for the root user.

The trick is to tell the script to run audiodevice as the currently logged in user. If you trust that Casper will pass you the value of the currently-logged in user when it runs the script, you can do this:

/usr/bin/sudo -u "$3" /usr/local/bin/audiodevice output "WavTap"

Otherwise, you'll want to extract the name of the current user logged into the system ("w | grep console | awk {'print $1'}" is one of many ways to do that) and substitute that for "$3".

Hope that helps! If you want to see the full script that I'm using, let me know and I'll post it. The veterans around here will probably laugh at it as the work of a complete n00b, but it does what we need it to do under the conditions we're asking it to perform.

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+11
  • Contributor
  • 82 replies
  • Answer
  • April 23, 2014

I have scripted it successfully. It took a while to figure out what was going on.

I'm guessing that the problem you're encountering is that the script doesn't seem to do anything when run by Casper? The audio input/output options are user-level options, not system-level options. When Casper runs the script, it does so as "root", so it simply sets the audio options for the root user.

The trick is to tell the script to run audiodevice as the currently logged in user. If you trust that Casper will pass you the value of the currently-logged in user when it runs the script, you can do this:

/usr/bin/sudo -u "$3" /usr/local/bin/audiodevice output "WavTap"

Otherwise, you'll want to extract the name of the current user logged into the system ("w | grep console | awk {'print $1'}" is one of many ways to do that) and substitute that for "$3".

Hope that helps! If you want to see the full script that I'm using, let me know and I'll post it. The veterans around here will probably laugh at it as the work of a complete n00b, but it does what we need it to do under the conditions we're asking it to perform.


Forum|alt.badge.img+7
  • Contributor
  • 71 replies
  • April 24, 2014

wait wait wait......

Where are you getting this "audiodevice"? Only thing in /usr/local/bin for me is my homebrew apps.


Forum|alt.badge.img+11
  • Contributor
  • 82 replies
  • April 24, 2014

I got this from http://whoshacks.blogspot.co.uk/2009/01/change-audio-devices-via-shell-script.html


Forum|alt.badge.img+13
  • Author
  • Contributor
  • 157 replies
  • April 24, 2014

Mike, that was it! I forgot that it was a user level.

Thanks!!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings