AudioDevice not scriptable?

Johnny_Kim
Contributor II

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!

1 ACCEPTED SOLUTION

mikeh
Contributor II

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 solution in original post

4 REPLIES 4

mikeh
Contributor II

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.

BaddMann
Contributor

wait wait wait......

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

mikeh
Contributor II

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

Johnny_Kim
Contributor II

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

Thanks!!