I've found this apple script - I am novice, so i want help in saving the output to a variable. I think it occurs, at the marked line, i've appended an image the text and the macro it self.
tell application "System Preferences"
reveal pane id "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "System Preferences"
tell tab group 1 of window "Sound"
click radio button "Output"
tell table 1 of scroll area 1
set selected_row to (first UI element whose selected is true)
set currentOutput to value of text field 1 of selected_row as text
tell application "Keyboard Maestro Engine"
setvariable "outputDevice" to currentOutput
end tell
-- display dialog currentOutput
end tell
end tell
end tell
end tell
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
but it might be simpler:
to just return the value from the script
choose the option (on the Execute Script Action) to save its result to a variable.
-ttype : device type (input/output/system). Defaults to output.
-n : cycles the audio device to the next one
-sdevice_name : sets the audio device to the given device by name
The price is that you have to have, or install, Xcode and Xcode's command line tools.
There are other tools that need these, and Xcode is free, so it may be work having in the long run.