Scripting Airfoil 3 with COM

⚠️ This is an archived article. It refers to functionality previously included in Airfoil for Windows 3. Current versions of Airfoil for Windows do not support scripting.

Airfoil for Windows 3.4, including later updates to Airfoil 3, supports full out-of-process COM scripting. This functionality should allow 3rd party apps in just about any language (that supports COM) to interact with and control Airfoil 3 for Windows.

For example, to get a list of all recent sources using Windows JScript:

var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");

var recentSources = airfoilApp.GetRecentSources();
for(var i = 0; i < recentSources.Count(); i++)
{
	var audioSource = recentSources.Item(i);
	WScript.Echo("Recent source " + i + " is " + audioSource.Name());
}

The following script checks to see if a particular application is running, and if it is, tells Airfoil to start capturing its audio:

var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");

var runningSources = airfoilApp.GetRunningSources();
for(var i = 0; i < runningSources.Count(); i++)
{
	var audioSource = runningSources.Item(i);
	WScript.Echo("Running source " + i + " is " + audioSource.Name());
	
	// The Id() method returns the full path to the source, so 
	// we have to look at just the ending.
	if(endsWith(audioSource.Id().toLowerCase(),"firefox.exe"))
	{
		airfoilApp.SetCurrentSource(audioSource);
	}
}

function endsWith(str, suffix) 
{
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

To list remote speakers that Airfoil for Windows can see, adjust their volume, and connect to any speaker that isn't currently connected:

var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil");
var speakerCollection = airfoilApp.GetSpeakers();

for (var i = 0; i < speakerCollection.Count(); i++)
{
	var speaker = speakerCollection.Item(i);
	WScript.Echo("Speaker " + i + " is " + speaker.Name() + "\n");
	
	// Set the volume to half and connect if it isn't already connected
	speaker.SetVolume(0.5);
	if(!speaker.Connected())
	{
		speaker.Connect();
	}
}

Finally, you can also request to be notified of various events, including when source metadata changes:

var airfoilApp = WScript.CreateObject("RogueAmoeba.Airfoil", "AirfoilApp_");
var metadataProvider = airfoilApp.GetCurrentMetadata(); 

function AirfoilApp_OnMetadataChanged()
{
	WScript.Echo("Metadata Was Changed.");
	if(metadataProvider.ProvidesTrackMetadata())
	{
		WScript.Echo("Current track: " + metadataProvider.Title());
	}
}

For other functionality provided by the scripting interface, beyond the examples above, you can download the complete documentation of the Airfoil 3 Scripting API:

Airfoil 3 for Windows API Documentation and Examples

← Airfoil for Windows Support