Scripting via AppleScript
Beginning with version 2.5, Audio Hijack Pro supports a full AppleScript suite. Just about anything you can do with the graphical user interface, you can now also script. The following is a brief overview of the object model that Audio Hijack Pro exposes. For a complete reference, see Audio Hijack Pro's Scripting Dictionary in Script Editor. If you are new to AppleScript, we recommend you pick up a copy of AppleScript : The Definitive Guide by Matt Neuburg, before proceeding.
Creating a session
Just like in the graphical interface, the Session is the main object of interest in the scripting interface. Unlike the graphical interface, each session in the scripting interface has a specific type: application session, radio device session, and system audio session. As should be clear, the type of the session specifies what kind of audio source it uses.
So, to create a new session, we use a standard AppleScript make new ... at ... statement, along with the type of session we want to create:Note that if you try to instantiate the session class (e.g. make new session), you will get an error. The session class is an abstract base class on which the other concrete subclasses inherit from.
Retrieving an existing session
Existing sessions can be accessed through the session element of the application class:
Accessing audio source attributes
Now that we have a session, we can configure its audio source. The source attributes available are dependent on the type of the session. Application sessions have targeted application and launch argument. Audio device sessions have input device and output device. And Radio sessions have frequency and output device.
Whenever files are involved, Audio Hijack Pro uses POSIX paths (/path/to/file), and not AppleScript files or aliases (Volume:path:to:file).
Note as well, that whenever an audio device is needed, you can retrieve them from the audio input and audio output elements of the application object:
set theNames to (name of every audio input) set aName to first item of (choose from list theNames without multiple selections allowed)Accessing schedule and timer attributes
A sessions schedule is accessible through the timer element:
The basic attributes of a timer are enabled, actions, start time and duration.
By default, new timers are in "one-shot" mode, where they are set to fire on a specific date. To turn them into "repeating" timers, you turn on any one of their "runs" attributes.
Accessing recording attributes
Most of Audio Hijack Pro's recording settings are simple attributes of the session:
The recording format, file size limit, and recording time limit attributes are a bit more complex, as they are represented by a special class (audio recording format and size or length limit).
Accessing effects attributes
Currently, the Effects system can not be directly accessed via AppleScript. If you'd like this in a future version, please contact us at audiohijackpro@rogueamoeba.com
Sending commands
Finally, there are the commands for hijacking:
start hijacking theSession start hijacking theSession relaunch yes --Avoids the relaunch alert stop hijacking theSession
And recording:start recording theSession stop recording theSession split recording theSession pause recording theSession unpause recording theSession
Putting it all together
A complete example script that shows how to put all these basic pieces together into one script, is available at: http://rogueamoeba.com/audiohijackpro/scripting/downloads/BasicExample.scpt