Posted on 04-23-2014 06:56 AM
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!
Solved! Go to Solution.
Posted on 04-23-2014 11:41 AM
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.
Posted on 04-23-2014 11:41 AM
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.
Posted on 04-24-2014 07:40 AM
wait wait wait......
Where are you getting this "audiodevice"? Only thing in /usr/local/bin for me is my homebrew apps.
Posted on 04-24-2014 08:02 AM
I got this from http://whoshacks.blogspot.co.uk/2009/01/change-audio-devices-via-shell-script.html
Posted on 04-24-2014 09:58 AM
Mike, that was it! I forgot that it was a user level.
Thanks!!