Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Toggle Two Playback Devices like Speaker and Headset

Description
This script will toggle between two different playback devices. You'll have to set the correct names of your audio devices on lines 13 and 18. You can view the names by right-clicking the DisplayFusion tray icon and browsing the Audio Devices sub-menu.
Language
C#.net
Minimum Version
Created By
Otakadelic64898
Contributors
-
Date Created
Aug 27, 2018
Date Last Modified
Aug 27, 2018

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		string defaultName = BFS.Audio.GetDefaultPlaybackSounds();

		//
		// Name of Speaker Device. You have to change the value to your system.
		//
		string spkName = "Realtek High Definition Audio";
		
		//
		// Name of Headset Device. You Have to change the value to your system.
		//
		string headsetName = "USB ";

		string newName = "";
		if (defaultName.Contains(spkName)) {
            newName = headsetName;
        } else {
            newName = spkName;
        }
		
		string[] audioDevices = BFS.Audio.GetPlaybackDevices();
		foreach (string device in audioDevices) {
			if (device.Contains(newName)) {
				BFS.Audio.SetDefaultPlaybackSounds(device);
				break;
			}		
		}
	}
}