Automatic Audio Switch

Discussion in 'Mac Programming' started by jorettig, Feb 11, 2014.

  1. jorettig, Feb 11, 2014
    Last edited by a moderator: Feb 11, 2014

    jorettig macrumors newbie

    Joined:
    Feb 11, 2014
    #1
    Hey,

    sorry, I'm an absouletly newbie in the field of mac programming. But I have programming experience in general.

    I have here a new headset and I want the mac to switch automatically Audio Input and Output to the headset, when it's plugged in.

    I found this code here:

    http://www.oreillynet.com/mac/blog/2006/07/applescript_audio_output_switc.html

    I renamed the headset but I got a fault. The event protocoll says:

    Code:
    tell application "System Preferences"
    	activate
    	set current pane to pane "com.apple.preference.sound"
    end tell
    tell application "System Events"
    	get UI elements enabled
    		--> true
    	click radio button "Output" of tab group 1 of window "Sound" of application process "System Preferences"
    		--> error number -1728 from window "Sound" of application process "System Preferences"
    end tell
    tell current application
    	activate
    end tell
    So in my opinion the script tries to select the 'Output' Radio Button, but doesn't find it. What is the problem here? Im using Mavericks.

    Can I modify the script, that it starts automatically, when the headset ist plugged in?

    Thanks,
    jorettig
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Is Applescript Editor allowed to control the computer? See thumbnail. Works here and I'm on Mavericks too.

    Code:
    tell application "System Preferences"
    	activate
    	set current pane to pane "com.apple.preference.sound"
    end tell
    tell application "System Events"
    	get UI elements enabled
    		--> true
    	click radio button "Output" of tab group 1 of window "Sound" of application process "System Preferences"
    		--> radio button "Output" of tab group 1 of window "Sound" of application process "System Preferences"
    end tell
    Result:
    radio button "Output" of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
     

    Attached Files:

Share This Page