Example scripts for Audio Hijack

← Return to Audio Hijack’s scripting center

Below, you'll find a few sample scripts that show how to use various aspects of the scripting API. See the Scripting API Reference for full details about the API.


Toggle Named Session

⬇ Download

Given the name of a session, toggle its running status.

let sessionName = "Automated Session"; //Set me to the target session

let session = app.sessionWithName( sessionName )

if( session.running )
	session.stop()
else
	session.start()


Toggle Named Block

⬇ Download

//Toggle a Block between on and off

// Replace "ExampleSessionName" with your session's name
// Replace "ExampleBlockName" with the name of the block you want to toggle Off/On

let sessionName = "ExampleSessionName";
let blockName = "ExampleBlockName";

let session = app.sessionWithName(sessionName);

if (session.blockWithName(blockName).disabled)
{
	session.blockWithName(blockName).disabled = false;
}
else
{
  session.blockWithName(blockName).disabled = true;
}


Set Recording XAttrs

⬇ Download

A Recording Stop script, showing how to pass completed recording files to a command line tool.

// set the "Where From" URL that appears in the Finder's Get Info window
// #needsFile 

let url = 'https://www.example.com/';
let filePath = event.file.filePath;
let cmd = 'xattr -w com.apple.metadata:kMDItemWhereFroms '

cmd += app.shellEscapeArgument(url) + ' ';
cmd += app.shellEscapeArgument(filePath) + ' ';
let [status, stdout, stderr] = app.runShellCommand( cmd );


Disable Recorder Blocks

⬇ Download

// disable all the Recorder blocks in a session
// #needsSession

if (event.session == null)
	return;

event.session.blocks.forEach( block =>
{
	if (block.name == "Recorder")
		block.disabled = true;
});


Mute Output Devices

⬇ Download

// mute the output devices in a session
// #needsSession

if (event.session == null)
	return;

event.session.blocks.forEach(block =>
{
	if (block.name == "Output Device")
		block.disabled = true;
});


Open Custom URL in Safari

⬇ Download

// Open Safari with a custom URL
// Here we generate a date-based URL, but other options might include calling out
// to another command-line tool to read one from a file.
//
// Scripts like this are intended to be set as "Session Start" scripts, that run automatically
// when a session begins

let cmd = 'open -b com.apple.Safari '

let date = new Date().toISOString().slice(0, 10);
let url = 'https://www.example.com/?date=' + date;

cmd += app.shellEscapeArgument(url) + ' ';

let [status, stdout, stderr] = app.runShellCommand( cmd );


← Return to Audio Hijack’s scripting center


← Back to Audio Hijack Support Center