Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
Josh Harwood
9 discussion posts
HELLO!

I know about the script that is made to switch to an audio device with a dynamic name.

Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
string[] audioDevices = BFS.Audio.GetPlaybackDevices();
foreach (string device in audioDevices)
{
if (device.Contains("SAMSUNG"))
BFS.Audio.SetDefaultPlaybackSounds(device);
}
}
}


But what if I have 2 audio devices with dynamic names that I want to switch through? How would I set that up? There are 2 scripts here on the forums that are perfect if they were combined. One script switches between devices with exact file names and the other switches to a device based on a wild card but not multiple. I need a combination of both.

Basically

If audio device contains "blah" but is NOT "blah" then switch to "blah"
Else switch to "blah2"

Thanks in advance!
Feb 13, 2017  • #1
User Image
Josh Harwood
9 discussion posts
bump
Feb 14, 2017  • #2
Keith Lammers (BFS)'s profile on WallpaperFusion.com
We should be able to write a script that does what you're looking for. We'll post it when it's ready :)
Feb 14, 2017  • #3
User Image
Josh Harwood
9 discussion posts
Quote:
We should be able to write a script that does what you're looking for. We'll post it when it's ready :)


Thank you very much, I can write code fine in VBS but C# I cannot figure out!
Feb 15, 2017  • #4
User Image
Josh Harwood
9 discussion posts
Bump, any status changes? I can write the code if you can put me in the right direction.
Feb 18, 2017  • #5
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
Sorry for the delay! I attached a script that should work for you in this post. Here's how to get it to work:

  • Download the file attached to this post
  • Open the DisplayFusion Settings window to the "Functions" tab
  • Click the "Add Scripted" button
  • In the window that pops up, paste the code from the file you downloaded in the first step
  • Change the two strings on line 17 to something that will match the names of your audio devices
  • Give the script a name, and a key combination if you want
  • Click OK to save and close that window, then OK again to save and apply your settings

I hope this works for you!
Feb 23, 2017  • #6
User Image
Josh Harwood
9 discussion posts
Quote:
Sorry for the delay! I attached a script that should work for you in this post. Here's how to get it to work:

  • Download the file attached to this post
  • Open the DisplayFusion Settings window to the "Functions" tab
  • Click the "Add Scripted" button
  • In the window that pops up, paste the code from the file you downloaded in the first step
  • Change the two strings on line 17 to something that will match the names of your audio devices
  • Give the script a name, and a key combination if you want
  • Click OK to save and close that window, then OK again to save and apply your settings

I hope this works for you!


Thank you very much! I'll give this a shot in a few!! Can we make this an official script? This is by far the easiest method to switch between audio devices.
Feb 23, 2017  • #7
User Image
Josh Harwood
9 discussion posts
So this didn't work. Mind you, I am not putting the full name of my devices in the audio devices field. Because the original script didn't require that. Does this require it?

The old script had a section like this

Code

string[] audioDevices = BFS.Audio.GetPlaybackDevices();
foreach (string device in audioDevices)
{
if (device.Contains("SAMSUNG"))
BFS.Audio.SetDefaultPlaybackSounds(device);
}


I don't see a "contains" section in your code
Feb 23, 2017 (modified Feb 23, 2017)  • #8
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
That's odd! You shouldn't need to put the full names of the devices. You just need to make sure that the names are different enough so that one of your items in the array doesn't match both of the audio devices you are trying to switch between. Could this be your problem?

This script doesn't use the contains method, but it uses a similar method called 'IndexOf' that does the same thing. I changed it to use this method because I wanted to ignore the casing. Ie. "headset" will now match "Headset", but it didn't before.

I hope this helps!
Feb 27, 2017  • #9
User Image
Josh Harwood
9 discussion posts
Quote:
That's odd! You shouldn't need to put the full names of the devices. You just need to make sure that the names are different enough so that one of your items in the array doesn't match both of the audio devices you are trying to switch between. Could this be your problem?

This script doesn't use the contains method, but it uses a similar method called 'IndexOf' that does the same thing. I changed it to use this method because I wanted to ignore the casing. Ie. "headset" will now match "Headset", but it didn't before.

I hope this helps!


Awesome looks like I had a typo....and I am a VBS programmer lol. Working now. Thank you for the excellent work. Anyway we can post this to the actual scripts area for other users?
Feb 28, 2017  • #10
Keith Lammers (BFS)'s profile on WallpaperFusion.com
I've added this Scripted Function to the repository :)
Feb 28, 2017  • #11
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)