Blog
Welcome to the Trioro Tech Blog.
On this blog we post some of the technical challenges and solutions that we've come across. From time to time we also post comments on new technology that we've come across.

Sunday, May 03, 2009

Skype AppleScript: Switching Audio

I fiddled around today trying to figure out how to get Skype on the Mac to effectively switch from using the buit-in mic and speakers to using my bluetooth headset (and then back again).

I'm using a MacBook Pro and a Jabra BT530 bluetooth headset.

After starting Skype, through trial and error I figured out the right sequence of events to connect my bluetooth headset to the computer and then change both the Mac system preferences and the Skype preferences to make this work:
  • Establish the bluetooth connection to the headset
  • Open the system preferences and change the audio input and output to use the bluetooth headset
  • Open the Skype preferences and change the audio input and output to use the bluetooth headset
It took awhile to realize that going into the system preferences was necessary. Without doing this, the bluetooth headset connection would work, but the audio wouldn't flip over to the headset.

Once this sequence was established, the AppleScript could be written:
Audio%20-%20Bluetooth.scpt

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.sound"

end tell

tell application "System Events"

if UI elements enabled then

try

tell application process "System Preferences"

tell tab group 1 of window "Sound"

click radio button "Output"

set selected of row 2 of table 1 of scroll area 1 to true

set deviceselected to "Jabra Headset"

set verbal_description to "Bluetooth Headset Now Active"

tell application "Finder"

set volume 7

end tell

end tell

end tell

tell application "System Preferences" to quit

on error

tell me to activate

display dialog "Please plug in the headset." buttons {"Whoops!"} default button 1

end try

else --GUI scripting is disabled

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

display dialog "Please check the box called \"Enable access for assistive devices.\"" buttons {"Okay"} with icon 1 default button 1

end if

end tell


tell application "Skype"

activate

send command "SET AUDIO_OUT IOBluetoothSCOAudioEngine_new:00-1d-82-18-ec-e6" script name "something"

send command "SET AUDIO_IN IOBluetoothSCOAudioEngine_new:00-1d-82-18-ec-e6" script name "something"

end tell

Here is the script to change back to using the built in audio: Audio%20-%20Mac.scpt

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.sound"

end tell

tell application "System Events"

if UI elements enabled then

try

tell application process "System Preferences"

tell tab group 1 of window "Sound"

click radio button "Output"

set selected of row 1 of table 1 of scroll area 1 to true

set deviceselected to "Built-in Output"

set verbal_description to "Built-in Output Now Active"

tell application "Finder"

set volume 7

end tell

end tell

end tell

tell application "System Preferences" to quit

on error

tell me to activate

display dialog "Please plug in the headset." buttons {"Whoops!"} default button 1

end try

else --GUI scripting is disabled

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

display dialog "Please check the box called \"Enable access for assistive devices.\"" buttons {"Okay"} with icon 1 default button 1

end if

end tell

tell application "Skype"

activate

send command "SET AUDIO_OUT AppleHDAEngineOutput:0" script name "something"

send command "SET AUDIO_IN AppleHDAEngineInput:1" script name "something"

end tell

These scripts were adapted from: http://www.oreillynet.com/mac/blog/2006/07/applescript_audio_output_switc.html

The one trick in modifying this for your own use is to use the "get" script to find out the name of the audio device you want to switch to in Skype.

tell application "Skype"

activate

send command "GET AUDIO_IN" script name "something"

--send command "GET AUDIO_OUT" script name "something"

end tell

As you switch settings in Skype and run this script, change the commented lines to switch between reading the audio input and output settings. Take the output from this script and replace the similar lines in the earlier scripts.

Additionally, when you're in the System preferences you may need to pay attention to which rows in the table on the output screen your devices are listed on. That part of the above script is also highlighted in red.

Labels: , ,

1 Comments:

At 6:36 PM, Anonymous Anthony said...

This is very useful and ideal for what I want to do, however it just doesnt work for me. I was on Skype 2.8 but it wouldnt even recognise my BT audio_in using your "get" script. Now I downgraded to 2.7, the "get" script works, but still the output/input won't change! The system prefs section works perfectly. Am I missing something? I checked other commands like CALL and HOOK ON, they work ok. Appreciate your help.

 

Post a Comment

Links to this post:

Create a Link

<< Home