Here is my solution that works. The scripting is not very elegant, so if anyone has suggestions to streamline the code it would be much appreciated
–get input sources available from Sound Pane of System Preferences
tell application “System Preferences”
reveal anchor “input” of pane id “com.apple.preference.sound”
end tell
tell application “System Events” to tell process “System Preferences”
set InputSource1 to (get value of text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound")
--Row 1 is always "Internal Microphone"
try
set InputSource2 to (get value of text field 1 of row 2 of table 1 of scroll area 1 of tab group 1 of window "Sound")
--Row 2, if it exists, is the just attached external microphone name
on error number -1719
--trap for error when no USB microphone attached
set InputSource2 to "External Mic not attached"
end try
end tell
quit application “System Preferences”
– get Users choice of audio input
set userCanceled to false
try
set dialogResult to display dialog ¬
“Please select your input source” buttons {InputSource1, InputSource2, “Cancel”} ¬
default button “Cancel” cancel button ¬
“Cancel”
on error number -128
set userCanceled to true
end try
if userCanceled then
set InputChoice to “User cancelled.”
– statements to execute when user cancels
display notification InputChoice with title “Alert”
setFilemakerpro(InputChoice)
else if button returned of dialogResult is InputSource1 then
set InputChoice to InputSource1
– statements to process input source is InputSource1
SetInputChoice(InputChoice)
setFilemakerpro(InputChoice)
else if button returned of dialogResult is InputSource2 then
set InputChoice to InputSource2
-- statements to process input source is InputSource2
if InputChoice is "External Mic not attached" then
display notification "There is no external microphone connected. Please connect one and try again later." with title "Alert"
setFilemakerpro(InputChoice)
else
SetInputChoice(InputChoice)
setFilemakerpro(InputChoice)
end if
end if
on SetInputChoice(InputChoice)
tell application "System Preferences"
reveal anchor "input" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
if InputChoice is "Internal Microphone" then
--Row 1 is always "Internal Microphone"
select text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound"
-- make sure ambient noise reduction is checked
if (get value of checkbox "Use ambient noise reduction" of tab group 1 of window "Sound") = 0 then
-- the value of the checkbox is 0 if unchecked; 1 if checked
click checkbox "Use ambient noise reduction" of tab group 1 of window "Sound"
end if
else
select text field 1 of row 2 of table 1 of scroll area 1 of tab group 1 of window "Sound"
--Row 2 is the external microphone
end if
end tell
tell application "System Preferences"
if InputChoice is "Internal Microphone" then
set volume input volume 100 -- set to maximum for interanl microphone
else
set volume input volume 75 -- set volume lower for external microphones
end if
(* other optional settings in sound pane
set volumeSettings to (get volume settings)
if (output muted of volumeSettings) then
display dialog “Volume: Muted”
else
set theVolume to (output volume of volumeSettings)
display dialog (("Volume: " & theVolume) as string)
end if
set volume alert volume 75
set volume input volume 50
set volume output volume 50
set volume without output muted
get volume settings
*)
end tell
quit application "System Preferences"
end SetInputChoice
on setFilemakerpro(InputChoice)
tell application "FileMaker Pro Advanced"
tell table "Preferences"
tell record 1
set cell "recordoptions1" to InputChoice --let Filemaker pro know which input to use
end tell
end tell
end tell
end setFilemakerpro
Model: macbook pro
AppleScript: 2.6.1
Browser: Safari 537.77.4
Operating System: Mac OS X (10.10)