You are here

AppleScripting iRed2

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:


How to find out the "right syntax"?

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:

ScriptingClips Popup

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.


IR Codes

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:

tell application "iRed2"
   every Device of Remote "Sony Main"
end tell


This is the output of the above AppleScript:

{Device "Sony/DAT" of application "iRed2", Device "Sony/CD" of application "iRed2", Device "Sony/Tape A" of application "iRed2", Device "Sony/Tape B" of application "iRed2", Device "Sony/Main" of application "iRed2", Device "Sony/Tuner" of application "iRed2", Device "Sony/Home Theater" of application "iRed2"}


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:




Transmit IR Codes


To make iRed2 transmit a specific IR code, ask the application to "perform" this "action", e.g.


tell application "iRed2" to perform action Code "Power" of Device "Sony/Home Theater" of Remote "Sony Main"


If the IR code is part of the archive rather than part of a remote, omit the "Remote" part:

tell application "iRed2" to perform action Code "Power" of Device "Panasonic/TV"


If you have multiple IR modules, you may even determine which IR module to use for transmission:

tell application "iRed2" to perform action Code "Power" of Device "Panasonic/TV" using module "Living Room" 


And finally, if your IR module has multiple LEDs built-in, you can address these individually or in groups:

tell application "iRed2" to perform action Code "Power" of Device "Panasonic/TV" using module "Living Room" using led "1"

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.


Other Actions

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".

tell application "iRed2" to perform action AppleScript "Next Album" of AAG "iTunes/Navigation"

The easiest way to find out how to perform a specific action is to use the Scripting Clips popup as described above.



To make handling of tuner-like devices easier, iRed2 has a special means for that. This also works for EyeTV (a description can be found in an Elgato's support document).

This example creates the necessary IR codes to make the magic happen:

perform action (TunerChange "RBB" of Tuner "Sony Bravia")


If this tuner is not part of the Library but rather located on a Remote, simply add the name of the remote:

perform action (TunerChange "Klassikradio" of Tuner "SonyTuner" of Remote "Sony Main") 

That easy :)

Please note that you cannot address specific IR modules for tuners, because the transmit module is already set from within iRed2:


Adressing "strange" action names

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.


Alternative Adressing using UUID

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:

tell application "iRed2" to perform uuid "3AD45589-79D9-4AF7-BD60-77C398432A10" on remote "Sony Main"



Calling iRed's actions from a web browser

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:

<a href="ired2://perform?uuid=3AD45589-79D9-4AF7-BD60-77C398432A10&remote=Sony%20Main">Tape Deck A</a>


After installation of iRed2, this link will call iRed and performs the respective action. Very handy!


"Clicking" a button or calling a trigger by AppleScript

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:

perform uuid "3AD45589-79D9-4AF7-BD60-77C398432A10" 


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:

tell application "Indigoserver"
    ignoring application responses
        execute group "Watch DVD"  -- this will call back iRed to transmit IR codes
    end ignoring
end tell



Switching from iRed 1.x

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.