Copyright © Rogue Amoeba Software, Inc. All rights reserved.
← Return to Audio Hijack’s scripting center
Audio Hijack’s built-in Automations will run your scripts in response to a variety of events, but sometimes you’ll want to trigger scripts to run on their own. This article covers various ways you can make that happen.
In its default state, Audio Hijack does not execute external scripts, as a security measure. To use this functionality, just enable it in the Settings window.
Once in Settings, click on the Advanced tab. Under the Scripting section enable the Allow execution of external scripts checkbox.
.ahcommand
filesBy far, the simplest way to have Audio Hijack execute a script is via a .ahcommand
file, hereafter referred to simply as a command file. This is nothing more than a (UTF-8 encoded) plain text file containing the script, with the file extension set to .ahcommand
.
Opening a command file will cause it to immediately execute in Audio Hijack.
While we’re 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 scripters.
The most practical of these would be the open
command-line utility in MacOS. This is done in the Terminal utility, by executing the following command:
open -b com.rogueamoeba.audiohijack SomeScript.ahcommand
That would cause SomeScript.ahcommand
to open in Audio Hijack and execute.
Going further, the open
command could be used with LaunchServices or cron
to periodically execute a script.
Command files can also be leveraged in other software. For instance, using the Elgato Stream Deck app, hardware can be configured to open command files by assigning buttons to the Open action.
Finally, both Apple's Shortcuts app and AppleScript provide a mechanism for opening files from the Finder, which can also be used to execute command files.
Speaking of Shortcuts, if you are using MacOS 12 (Monterey) 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 that script when the action triggers. If you like to keep all your scripts organized in the Script Library window, it’s an easy way to access those options outside the app.
On the other hand, the Run Javascript action is configured using a script written inside of the Shortcuts app directly. If you prefer your Shortcut workflow to be entirely self-contained, you can keep all the relevant parts right in the Shortcuts app.
Whichever method you choose, be aware that you can also execute your Shortcuts workflows from the command line. Apple’s Shortcuts User Guide provides those details.
← Return to Audio Hijack’s scripting center