Keyboard Maestro Macro to Toggle Sound Devices

I cobbled together a group of macros for toggling the input and output audio devices on my Mac.1 I’m using some basic AppleScript and Keyboard Maestro.

Here’s the structure of the macro group.

Two high level macros execute the individual actions to switch an input or output source. I like this structure because I can mix and match input or output as needed. As an example, the “Record” macro runs the “Audio Input Rode” and “Audio Output Rode” macros. The result is what the name implies.

I bound the group to Control+Option+P to show a panel of selections.

The AppleScript to switch the Input source is as follows:

:::applescript
tell application "System Preferences"
    activate
    set current pane to pane id "com.apple.preference.sound"
end tell
tell application "System Events"
    tell process "System Preferences"
        set frontmost to true
        --get properties of UI element of tab group of window "Sound"
        click radio button "input" of tab group of window "Sound"
        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 "Rode Podcaster" then
                set selected of aRow to true
                exit repeat
            end if
        end repeat

    end tell
end tell
tell application "System Preferences" to quit

Switching the Output source only requires one line change:

:::applescript
tell application "System Preferences"
    activate
    set current pane to pane id "com.apple.preference.sound"
end tell
tell application "System Events"
    tell process "System Preferences"
        set frontmost to true
        --get properties of UI element of tab group of window "Sound"
        click radio button "output" of tab group of window "Sound"
        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 "Rode Podcaster" then
                set selected of aRow to true
                exit repeat
            end if
        end repeat

    end tell
end tell
tell application "System Preferences" to quit

I’ve borrowed heavily from Mac OS X Hints and Macsripter.2

This is just too useful to keep to myself. The macro group can be found with the rest of my half-ass Keyboard Maestro macros on Github.

Rock-on little podcasters.


  1. I know about soundsource but it is not working on 10.8 yet. ↩︎

  2. Ok, I copied. That’s what scripters do. We’re pretty far from the metal. ↩︎