I have pretty much managed it save one final detail, namely getting it to switch the audio output to the TV as well.
This is my code
Code: Select all
[MeasureWin7Audio]
Measure=Plugin
Plugin=Win7AudioPlugin
[measureDisplay]
Measure=Calc
Formula= #switch#
DynamicVariables=1
UpdateDivider=-1
IfCondition=measureDisplay = 0
IfCondition2=measureDisplay = 1
IfTrueAction=[C:\Windows\System32\DisplaySwitch.exe /external][!CommandMeasure "MeasureWin7Audio" "SetOutPutIndex 1"][!SetOption MeasureLoop EndValue 10][!SetOption MeasureLoop Increment 2][!SetOption MeasureLoop InvertMeasure 1][!UpdateMeasure "MeasureLoop"][!CommandMeasure MeasureLoop "Reset"]
IfTrueAction2=[C:\Windows\System32\DisplaySwitch.exe /extend][!CommandMeasure "MeasureWin7Audio" "SetOutPutIndex 7"][!SetOption MeasureLoop EndValue 10][!SetOption MeasureLoop Increment 2][!UpdateMeasure "MeasureLoop"][!SetOption MeasureLoop InvertMeasure 0][!CommandMeasure MeasureLoop "Reset"]
[!CommandMeasure "MeasureWin7Audio" "SetOutPutIndex 1"] for the first IfTrueAction
[!CommandMeasure "MeasureWin7Audio" "SetOutPutIndex 7"] for the second
The other stuff relates to it playing an animation and actually switching the screen over.
Here is a picture of my Audio Devices window:
As you can see the 1st item is my computer speakers and the 7th is SAMSUNG-4 which is my TV.
In the picture the SAMSUNG-4 is "Not Plugged in" but when I activate the 2nd display it becomes "Ready" and the audio switches to item 3 which is "Digital Audio (S/PDIF)" (I must admit I dunno what that is!) NOT item 7 as requested.
I originally thought that this might be happening because when the switch occurred in rainmeter the screen was still not active, so I programmed a 5-10 second delay on the Win7Audio switch to give the screen time to register as connected. Which made no difference.
In fact if I "SetOutPutIndex" to anything greater than 1 it ALWAYS selects Item 3, "Digital Audio (S/PDIF)".
So as a test I disabled this device. It then wouldn't switch to anything, remaining on the speakers . . . . even after I re-enabled "Digital Audio (S/PDIF)".
I get the feeling that Win7Audio populates its list of devices when it first starts up and from then on does not ever add new ones (although it does appear to take them away when disabled!), so unless the screen is on when windows starts (which I definitely don't want) it will never work.
Is this correct?
If so is there any other way of getting rainmeter to switch the default audio device?
I saw something about doing it using AudioLevels? I went with the Win7Audio option as it seemed easier and more fit for purpose!