AppleScripts are very powerful on the Mac and allow to do many different things. We won't go into all the possibilities of AppleScripts here, but rather go through how to use them with OnTheAir Node, OnTheAir Live and OnTheAir Manager.
Note that OnTheAir Node can trigger AppleScripts, but OnTheAir Node is not AppleScriptable, so you can not control it with AppleScripts. OnTheAir Node can only be controlled either by the Telnet or the REST API.
Where to find and save AppleScripts ?
When you install OnTheAir Node, some sample AppleScripts samples are pre-installed so it is easy to start with and understand the way it works. They are located in the following folder:
/Library/Application Support/OnTheAir Node/AppleScript/
As soon as an AppleScript file (.scpt) is placed in this folder, it will appear in the attributes list of OnTheAir Live or OnTheAir Manager.
WARNING:
AppleScripts are only loaded when the application starts. If you modify the AppleScript and save it, you will have to stop and restart OnTheAir Node for the modification to be considered. If you use a different name, then it should be added though, it is just that we don't have an update mechanism.
How is an AppleScript triggered in OnTheAir Live or OnTheAir Manager ?
To understand a bit more how Attributes in general (not only AppleScripts) work in OnTheAir Node, Live and Manager, you may want to read this article first.
When AppleScripts are saved in the folder "/Library/Application Support/OnTheAir Node/AppleScript/", they automatically show up in the inspector of OnTheAir Live or OnTheAir Manager in "Inspector > Attributes > Built-In". See how it should look like by default :
On the screenshot above, you can see that there are two sample AppleScripts that should already be installed. If you can't see any ApplesScript in the inspector, please check that the 2 AppleScripts are indeed in the folder "/Library/Application Support/OnTheAir Node/AppleScript/". Also, if you don't want to see those AppleScripts in the inspector, you can simply delete them from the folder.
How does that work?
The behaviours of this attribute will depend on how you have written the AppleScript. But below
When is an AppleScript triggered?
Everything depend on the value entered in the text field of the attribute. For example in the screenshot below, we have set to value of the attribute "AppleScript: MovieRecorder Record" to "This is My Clip"
In OnTheAir Node, an AppleScript is triggered only when the current clip's attribute value is different than the previous clip's attribute value.
For example, let's say you have this type of playlist:
- Clip 1 - Attribute =
- Clip 2 - Attribute = "This is My Clip"
- Clip 3 - Attribute = "This is My Clip"
- Clip 4 - Attribute =
- Clip 5 - Attribute =
The AppleScript will be triggered at the beginning of "Clip 2", and "Clip 4".
Can I "pass" some variables to the AppleScript?
Currently, you can only "pass" the value of the text field to the AppleScript. So it has to be set manually, it is not yet possible to pass the name of the currently playing clip for example.
Sample AppleScripts
Below we explain the behaviour of the 2 AppleScript samples that are provided when you install OnTheAir Node.
"MovieRecorder Record"
Note that for the sample AppleScript to work, you must have MovieRecorder installed and configured on the Mac that is running OnTheAir Node.
The "AppleScript: MovieRecorder Record" is a sample that will start recording in MovieRecorder when a clip start, and stop the recording when the recording stops.
Let's say you have a playlist with clips A, B, C and D:
- Select clips B and C in your playlist
- Open the inspector
- Go to the "Attributes" tab, and open the "Built-in" section
- Tick the checkbox in front of "AppleScript: MovieRecorder Record"
- In the field below, enter for example the name of the clip that is playing:
- Now start playing clip A
- When you will skip to clip B, MovieRecorder will:
- change its recording name to the text you have set in the field
- and start recording
- When you will skip to clip C, MovieRecorder will continue recording (as you had the same attribute set)
- And when you will skip to clip D, MovieRecorder will stop recording
You can see that you can select multiple clips (in Manager you can even select a whole playlist or event), and that
- an action will be performed at the beginning of the clip(s), playlist, event (in the example above = start recording)
- a different action can be performed when the clip(s), playlist, event ends (in the example above = stop recording)
"Select Music Playlist"
The "AppleScript: Select Music Playlist" is a sample that will start playing a playlist in iTunes when it is triggered. For that, let's say you have a playlist with clips A, B, C and D
- Select clips B
- Open the inspector
- Go to the "Attributes" tab, and open the "Built-in" section
- Tick the checkbox in front of "AppleScript: Select Music Playlist"
- In the field below, enter exactly the name of the iTunes playlist you want to start playing
- Now start playing clip A
- When you will skip to clip B, iTunes should start playing your iTunes playlist
Writing AppleScripts
Open the sample we provide in the folder "/Library/Application Support/OnTheAir Node/AppleScript/" to have a look at how the Scripts can be written and start from there, but below are some guidelines.
An important reminder:
- when you create new scripts, they are immediately added to OnTheAir Node attributes and usable
- but when you modify a script that was already used by OnTheAir Node, you will have to stop and restart OnTheAir Node for the modification to be considered. Indeed OnTheAir Node does not monitor the scripts to see if they have changed and reload them. The AppleScripts are only loaded when the application starts or when new AppleScripts are added. Alternatively, you can remove the AppleScript from the folder and add it back.
So if you have a look at the sample MovieRecorder AppleScript, which look like this:
on action(inParam) ignoring application responses tell application "MovieRecorder" tell first source if (inParam is not "") then set recording name to inParam record else stop end if end tell end tell end ignoring end action
There are the first 2 lines which are required:
-
"on action" is required because we need to pass an argument.
- "ignoring application responses": as the AppleScript is performed on the main thread, we want to ignore the reponses from the application. If not ignored, and the application does not respond, it will block OnTheAir Node.
Then you have to tell the AppleScript to which application you are talking to, and with MovieRecorder you have to tell to which source you are talking to. Then comes the interesting part:
if (inParam is not "") then set recording name to inParam record else stop end if
This basically tells that:
- as long as the Attribute field is empty, nothing happens
- but then if you enter a value in the Attribute of a clip (inParam is not ""), then when the clip start playing :
- we will change to recording name of the 1st source of MovieRecorder to what you have typed in the Attribute field of the AppleScript
- then we start recording
- then as long as there is a value in the Attribute field, nothing will happen
- and when the attribute field is empty again, we will stop the recording in MovieRecorder
Comments
0 comments
Please sign in to leave a comment.