All actions which are created in iRed can also be triggered "from the outside". If you are using Indigo from Perceptive Automation, for example, or Salling Clicker to control Infrared from your mobile phone, you want to use AppleScript to trigger iRed's actions.
iRed2 has an AppleScript dictionary built in, so if you want to see all classes, properties and commands which iRed2 understand, simply drag-n-drop iRed2's application icon onto the icon of "Script Editor", which is located in "/Applications/AppleScript":
Script Editor will show iRed2's dictionary:
Built into the Action Editor, you'll find a popup "Scripting Clips". Just select the desired action in the Action Editor, then choose the appropriate popup menu item:
After using this popup, an appropriate clip is on your clipboard, i.e then open Script Editor for example and "paste in" the respective AppleScript snippet, in this case perform action (Code "Tape" of Device "Sony/Main" of Remote "Sony Main").
To "click" a button on a remote by AppleScript or call a trigger, please see the chapter below.
To address an action, you have to know something about the structure of iRed2's archive. iRed2's documents are called "Remotes", these are identificable by their title as listed in the main window:
The selected remote is addressed in AppleScript as Remote "Main-small", while the name of underlying file is filename of Remote "Main-small", which is "Sony-RM-S311-small.ired2rc" in my screenshot.
Every Remote as well as iRed2's archive itself, holds actions, which are of kind IR code, AppleScript, keystroke or mouse actions. IR codes are compiled in "Devices" (for remote controls), which are further grouped by "maker" and "name". Huh? This little example makes it more clear:
This is the output of the above AppleScript:
You see that every Device is named by its maker and a name. So the script maker of 1st Device of Remote "Sony Main" leads to "Sony", or name of last Device of Remote "Sony Main" is "Home Theater".
This two-level-structure is also reflected in iRed2's action browser and action editor:
To make iRed2 transmit a specific IR code, ask the application to "perform" this "action", e.g.
If the IR code is part of the archive rather than part of a remote, omit the "Remote" part:
If you have multiple IR modules, you may even determine which IR module to use for transmission:
And finally, if your IR module has multiple LEDs built-in, you can address these individually or in groups:
You can address single LEDs starting with 1 up to the number of LEDs, or use "external", "internal" or "all" for the respective group of LEDs.
iRed2 also contains other actions to control applications by AppleScript, Mouse action or Keystrokes. Actions are organized in "AAGs", short for "Application Action Groups". AAGs also have two levels for structuring, here these are "application" and "group".
The easiest way to find out how to perform a specific action is to use the Scripting Clips popup as described above.
If this tuner is not part of the Library but rather located on a Remote, simply add the name of the remote:
That easy :)
Please note that you cannot address specific IR modules for tuners, because the transmit module is already set from within iRed2:
If your action's name is using special characters like umlauts (äöü), or ;._/#"*, this name may not be usable in an AppleScript. To circumvent this, you'll find the text field "Name for scripts" on the bottom of the Actions Editor. If a name is entered there, it will take precedence over the action's name.
The path argument depends on the name of the device, the name of the code, etc. If you later change the path to the IR code, the AppleScript will not work anymore. As an alternative, you may decide to use an UUID, that is a "universal unique identifier" which never changes. This is an example for the uuid AppleScript syntax:
Looking into the popup shown above, you may have noticed the items reading "ired2://...". Well, that's an easy way to adress iRed's actions from a web page. With a HTML editor you may enter a link which changes the channel of your tuner, e.g.:
(Similar like before, you can omit the remote part here to address actions in the Library)
In HTML the full link reads:
After installation of iRed2, this link will call iRed and performs the respective action. Very handy!
Starting with iRed2 V2.1.1 you can also target remote buttons and triggers. This is only possible by using the uuid syntax (see above). To find the right UUID, go to the "Multiple Action Inspector" by clicking the "More..." button, either on the button inspector or on the trigger inspector.
On the Multiple Action Inspector you'll find the button to copy a "Scripting Clip" to your clipboard, ready to be pasted into an AppleScript code.
The AppleScript clip then looks like:
All settings of the button including module and LED settings are respected. You don't need to specify the remote's name, though.
Long delays in AppleScript actions? Be careful when you call a second app from within iRed which then calls iRed back in turn. This may lead to a deadlock or to several seconds delay at best. To provent from this, you may use the special AppleScript syntax ignoring application responses as shown in this example:
If you have AppleScripts used with iRed 1.x, there are some changes necessary. The main difference is the application's name which has changed from "iRed" to "iRed2". Wow, big change!
The real difference comes from the new 3-level assorting of iRed2's actions. In iRed 1, an ir code was adressed by its name and the name of the remote (e.g. "Sony/Power"), now a 3rd level - the model name - is mandatory, e.g. "Sony/Amplifier/Power". The same applies to AppleScripts as well. If you omit the middle component, iRed2 will look for a non-ambiguous action with the respective name, but this will fail if you have several components of the same make or many AppleScripts under the same application name.
Though I have made some efforts to let you use your scripts unchanged, I recommend to switch to the new syntax. Please tell me when your favorite AppleScript is not working anymore.