Running Audio Hijack scripts via external triggers

← Scripting Center

Although Audio Hijack's built-in Automations will run your scripts in response to a variety of events, sometimes you need to be able to trigger scripts to run on their own. This article covers the various ways to make that happen.

Initial Setup: Preferences

Out of the box, Audio Hijack does not allow any external script execution. This is a security measure to make it harder for possibly malicious scripts to run. For the individual scripter needing the functionality though, this can be safely bypassed.

Simply open the Preferences window, click on the "Advanced" tab, and then under the Scripting header, turn on the "Allow execution of external scripts" checkbox.

Preferences Window

Command files: .ahcommand

By far the simplest way to have Audio Hijack execute a script, is via a ".ahcommand" file, here after refered to simply as a command file. This is nothing more than a text file (UTF-8 encoded) containing the script, with the file extension set to ".ahcommand".

Simply opening a command file in Audio Hijack, will cause it to immediately execute.

Command File Screenshot

And while we are all familiar with double-clicking on a file to open it, there are many other ways of opening files (and thus executing command files) that are useful to scriptors.

The most useful of these, would be the "open" command-line utility in MacOS. In Terminal, executing a command such as: open -b com.rogueamoeba.audiohijack SomeScript.ahcommand , will cause SomeScript.ahcommand to open in Audio Hijack, and thus execute.

Going further, if one wanted to periodically execute a script, the "open" command above could be used with LaunchServices (or cron).

Finally, both Shortcuts and AppleScript provide a mechanism for opening files, which can also be used to execute command files.

Shortcuts Actions

Speaking of Shortcuts.app, if you are using MacOS 12 or later, it too can be used to execute scripts in Audio Hijack. Audio Hijack provides two shortcut actions for this purpose, "Run a Script", and "Run Javascript".

The "Run a Script" action, allows you to select an existing script from Audio Hijack's "Script Library" window, and will execute it when the action executes. If you like to keep all your scripts organized in the Script Library window, this is an easy way to access one.

Shortcuts.app Window

The "Run Javascript" action, is configured with a script inside of it directly. If you prefer your Shortcut workflow to be entirely self-contained, is a good way to keep all the relevant parts right in Shortcuts.app.

Shortcuts.app Window

Whichever method you choose, also be aware that you can also execute your final Shortcut workflows from the command line. See Apple's documentation "Run shortcuts from the command line" for full details.