Toggle Audio Outputs
This script will allow you to toggle between two Audio output options in the Sound Preference Pane, and will display the name of the selected output on the Mac's monitor and the T68i. Clicking "Yes" will quit System Preferences, "No" will keep System Preferences open. I use this to toggle between my Mac's speakers, and an optical "TOSlink" connection to my home stereo. Used in conjunction with the iTunes scripts, I can now listen to my iTunes library on my home stereo without ever having to sit in front of my Mac. NOTE: This script requires Apple's GUI Scripting Component. NEW! Stephane Brau helped identify a problem with this script while using a non-US English system. The script needs to be altered to use the proper names of the Preference Panes and controls in the language of your OSX installation. Here's the French version. (compiled AppleScript) Thanks for the help!
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell application process "System Preferences"
set frontmost to true
click menu item "Sound" of menu "View" of menu bar 1
if my wait4window("Sound") is false then return false
tell window "Sound"
tell tab group 1
tell radio button "Output"
click
end tell
(* You can add your own audio output descriptive text, such as "iMic USB Audio", in the next section. *)
if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 1 of table 1 of scroll area 1 to true
try
tell application "SEC Helper"
show screen message "Audio Out Option 1"
enter popup mode text "Audio Out Option 1"
end tell
on error
beep
end try
else
set selected of row 2 of table 1 of scroll area 1 to true
try
tell application "SEC Helper"
show screen message "Audio Out Option 2"
enter popup mode text "Audio Out Option 2"
end tell
on error
beep
end try
end if
end tell
end tell
end tell
end tell
on wait4window(this_title)
tell application "System Events"
tell process "System Preferences"
repeat with i from 1 to 60
if the name of window 1 is this_title then return true
delay 1
end repeat
end tell
end tell
return false
end wait4window
on affirmative_popup_response()
tell application "System Preferences" to quit
end affirmative_popup_response
on negative_popup_response()
(* Don't have to do anything...but keep this section for SEC Helper compatibility *)
end negative_popup_response
|