Need help having a computer automatically select a usb sound input

I am trying to set up a workstation that uses a Logitech USB Headset for the mic inputs, ann audio out from the computer.

I wrote this applescript, which works correctly about half of the time.

s
et volume output volume 50 --> number from 0 to 100
	
	--set system input sound level
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.sound"
	end tell
	tell application "System Events" to tell process "System Preferences"
		click radio button "Input" of tab group 1 of window "Sound"
		select row 3 of table 1 of scroll area 1 of tab group 1 of window "Sound"
		tell slider 1 of group 2 of tab group 1 of window 1 to set value to 10
	end tell
	tell application "System Events" to tell process "System Preferences"
		click radio button "Output" of tab group 1 of window "Sound"
		select row 2 of table 1 of scroll area 1 of tab group 1 of window "Sound"
		click button 1 of window "Sound"
	end tell
	
	quit application "System Preferences"

The problem is that sometimes the computer will select the built in mic as in input and completely ignore the USB Headset.

What confuses me is that that the applescript is correct as far as selecting the correct row that reflects that I want the usb headset.

I was wondering if anyone has any ideas on what I can do to have the computer automatically select the correct USB Headset for both inputs and outputs.

The name of the headset is Logitech USB Headset
I need the system volume to be at 50%
I need the mic sound input levels to be at 100%
And I need the computer to use the USB Headset for all sound output as well as inputs.

Is there a shell script that would do this, or is there a way to tell the computer to select the USB device by name and not row?

The problem is this computer is for younger students that are unable to select the sound inputs themselves.

The computers are using 10.5.8 and one is using 10.6.1

Thank you for all of your help.

Regards,
Paul Allen

I combined some applescripts to this, maybe this would be more accurate.

I was thinking maybe an applescript along these line…

set volume output volume 50 --> number from 0 to 100

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"
					if (selected of row 3 of table 1 of scroll area 1) then --headset is selected
						set selected of row 1 of table 1 of scroll area 1 to true
						set deviceselected to "Line Out"
						set verbal_description to "Line out."
						tell application "Finder"
							set volume 7
						end tell
					else
						set selected of row 3 of table 1 of scroll area 1 to true
						set deviceselected to "Logitech USB Headset"
						set volume output volume 50 --> number from 0 to 100
					end if
				end tell
			end tell
			tell application "System Preferences" to quit
			tell me to activate
			display dialog "Audio output is now..." & return & return & "* " & deviceselected buttons {"Rock on"} default button 1 giving up after 3 with icon stop
		on error
			tell me to activate
			display dialog "Please plug in the headset." buttons {"Whoops!"} default button 1 with icon caution
		end try
	else --GUI scripting is disabled
		do shell script ¬
			"touch /private/var/db/.AccessibilityAPIEnabled" password ¬
			"pwd" with administrator privileges
		
	end if
end tell

Regards,
paulmattallen