Example scripts for Audio Hijack

← 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()


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 

function shellArgEscape (arg) { return `'${arg.replace(/'/g, `'\\''`)}'`; }

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

cmd += shellArgEscape(url) + ' ';
cmd += shellArgEscape(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

function shellArgEscape (arg) { return `'${arg.replace(/'/g, `'\\''`)}'`; }

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

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

cmd += shellArgEscape(url) + ' ';

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