Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator - Toggle Sound Output Device

Hi.
I have an audio interface with headphone output, and the internal imac speakers. I like to toggle between them very often Right now I have to open system prefs, click on sound, and select the sound output. This is a pain. Ideally, I would like a keyboard shortcut t do this for me, but I can't find a way to do it. I had a play with automator and thought I'd solved it by getting it to record me changing sound output - but it didn't work.

Can anyone give me some relatively simple instructions on how to make this task feasible?

iMac 24" 2.4Ghz; iBook 14" 1Ghz, Mac OS X (10.5.1)

Posted on Feb 27, 2008 3:01 PM

Reply
Question marked as Best reply

Posted on Feb 27, 2008 4:00 PM

Automator can not do this. Try Soundsource http://www.versiontracker.com/dyn/moreinfo/macosx/18988

Also check out the following link:
http://www.macosxhints.com/article.php?story=20050614171126634
That one might be outdated as it was made for Tiger.
6 replies

Jan 9, 2015 11:15 AM in response to Dreyfuzz

edit: (i know it's a 3 year old thread)


not sure why you would say that automator can't do it. if you can do it with a gui, there is almost certainly a way to do it using automator. this is what i use for os x to switch to bluetooth (using ifttt to trigger a certain playlist when i'm almost home).


tell application "System Preferences" to set current pane to pane id "com.apple.preference.sound"

tell application "System Events"

tell process "System Preferences"

tell window "Sound"

click (radio button 2 of tab group 1)

delay 0.0

select row 2 of first table of first scroll area of first tab group

delay 0.0

end tell

end tell

end tell


tell application "System Preferences" to quit

Jul 25, 2016 3:50 AM in response to mouseandcat1

This works a treat - thank you!!

Also found this script - but yours works better.



An AppleScript to change sound output device User uploaded file
Jun 28, '05 09:18:00AM • Contributed by: Miraglia


The goal of this small AppleScript is to be able to change the sound output device quickly and easily. Without using Accessibility Controls, the process usually involves mousing to the System Preferences, mousing to and clicking on the Sound control, then mousing to and clicking on the desired output.


If you wire this script to a keyboard shortcut (using, for example, FastScripts from Red Sweater), you can choose your default source without mousing at all.


This first version gets the list of possible outputs, and presents a dialog with buttons enabling you to choose the output source. The return key triggers your default choice without touching the mouse (replace "SoundSticks" in the script with the name of your preferred default).

tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows copy (value of text field 1 of aRow as text) to the end of theOutputs end repeat tell application "Finder" activate set desiredOutput to display dialog ¬ "Choose Sound Output: " buttons theOutputs default button "SoundSticks" end tell repeat with aRow in theRows if (value of text field 1 of aRow as text) is equal to ¬ (button returned of desiredOutput as text) then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit
And next, a streamlined version that switches to your desired default source without asking you for input. Change the text "SoundSticks" in the script to the name of your desired output source.
tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows if (value of text field 1 of aRow as text) ¬ is equal to "SoundSticks" then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit
This second version is useful if, for example, you are a laptop user who frequently plugs into and then disconnects from an external sound output like SoundSticks. Upon plugging in, this script allows you to select the external sound output with a single keyboard shortcut (again, assuming that you have a utility for launching scripts via user-defined keyboard shortcuts).


Jul 25, 2016 4:10 AM in response to simplesime

This works a treat - thank you!!


It was my intention to have this script run as an application, so upon login to account or start up of OSX (Currently using 10.11.5 El Capitan) so I saved the run applescript as an application in Automator

User uploaded file

then added it to dropbox so my system would always be able to access it locally, then in user pane of system prefs add the application as a start up item.


Security pref/Privacy - Allow apps below to control your computer - check on the script app you just made so the automator workflow can do its thing.

User uploaded file

Once you let the system boot up - your audio output line will automatically be selected.


User uploaded file



Also found this script below - but yours 'mouseandcat1's works better.



An AppleScript to change sound output device User uploaded file
Jun 28, '05 09:18:00AM • Contributed by: Miraglia


The goal of this small AppleScript is to be able to change the sound output device quickly and easily. Without using Accessibility Controls, the process usually involves mousing to the System Preferences, mousing to and clicking on the Sound control, then mousing to and clicking on the desired output.


If you wire this script to a keyboard shortcut (using, for example, FastScripts from Red Sweater), you can choose your default source without mousing at all.


This first version gets the list of possible outputs, and presents a dialog with buttons enabling you to choose the output source. The return key triggers your default choice without touching the mouse (replace "SoundSticks" in the script with the name of your preferred default).

tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows copy (value of text field 1 of aRow as text) to the end of theOutputs end repeat tell application "Finder" activate set desiredOutput to display dialog ¬ "Choose Sound Output: " buttons theOutputs default button "SoundSticks" end tell repeat with aRow in theRows if (value of text field 1 of aRow as text) is equal to ¬ (button returned of desiredOutput as text) then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit
And next, a streamlined version that switches to your desired default source without asking you for input. Change the text "SoundSticks" in the script to the name of your desired output source.
tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows if (value of text field 1 of aRow as text) ¬ is equal to "SoundSticks" then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit
This second version is useful if, for example, you are a laptop user who frequently plugs into and then disconnects from an external sound output like SoundSticks. Upon plugging in, this script allows you to select the external sound output with a single keyboard shortcut (again, assuming that you have a utility for launching scripts via user-defined keyboard shortcuts).


Automator - Toggle Sound Output Device

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.