Thanks a lot RodgerWW, you gave me the answer I was looking for (and thanks to "Lri" of course). Here is my new version of the script :
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Son"
click radio button "Sortie"
if (selected of row 3 of table 1 of scroll area 1) then
set selected of row 4 of table 1 of scroll area 1 to true
set deviceselected to "HEADSET"
return "HEADSET"
else
set selected of row 3 of table 1 of scroll area 1 to true
set deviceselected to "MAC"
return "MAC"
end if
end tell
end tell
quit application "System Preferences"
- With that I don't need anymore to have a separate script to tell application System Preferences to quit !
- I don't have anymore the System Preferences pane which open and pop-up on the screen !
- If you have an english system (like most of you I think), you will have to change "SON" by "SOUND" and "SORTIE" by "OUTPUT"
- Also, you will have to change "ROW 4" by the number corresponding to the sound output you want to be selected. Same thing for the "Else" where you have "ROW 3". You can find which "number" it is for you by "control-click" the sound icon on your menu bar : here you'll find the list of all your sound output options in order (1,2,3...).
And here is the new link to download the new resulting workflow if you wish : https://www.box.com/s/79iprwo8nehs0v7bzin6
Hope you will like it ;-)