MCE Remote on a Mac – Step 3: configuring LIRC in OS X

MCE Remote on a MacThis is part 3 in a series on using an MCE Remote Control with a Mac. See the:
- Main article
- Step 1: installing Finnix as a Parallels VM
- Step 2: installing LIRC in the Finnix VM

Installing LIRC using MacPorts

The LIRC client executables can be installed using MacPorts. We will use these executables to connect to the LIRC daemon in the Finnix VM.

First you need to install:

Then fire up a terminal, and execute the following commands in a Mac terminal to initialize your ports tree and install LIRC:
$ sudo port -v selfupdate
$ sudo port install lirc

While you are waiting for lirc to install, let’s already execute the next step: in order to connect to your virtual machine, you need to know the IP address used by it. Run the ifconfig command in your Finnix VM. The output looks someting like:
root@tty1:~# ifconfig eth0
eth0    Link encap:Ethernet HWaddr 00:1c:42:f0:e5:19
        inet addr:10.37.129.3 Bcast:10.37.129.255 Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
        RX packets:813 errors:0 dropped:0 overruns:0 frame:0
        TX packets:145 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:73804 (72.0 KiB) TX bytes:11687 (11.4 KiB)
        Interrupt:10 Base address:0x8200

The ip address you are looking for is the one after ‘inet addr:’ on the second line.

When lirc is installed, let’s connect to it by typing the following in your Mac terminal (and not the Finnix VM), obviously replacing the ip address with the one you found in the previous step:
# sudo lircd --connect 10.37.129.3
# sudo chmod 666 /opt/local/var/run/lircd

Now let’s test your setup by running ‘irw’ and pushing some buttons. Your terminal should look like:
# irw
000000037ff07bf2 00 Home mceusb
000000037ff07bf2 01 Home mceusb
000000037ff07bf2 02 Home mceusb
000000037ff07be9 00 Play mceusb
000000037ff07be0 00 Down mceusb

Congratulations! You are now receiving your MCE Remote events on your Mac. Read on for information on how to control an application with it.

Controlling VLC with LIRC

This tutorial will now show you how to control the VLC media player using your MCE remote by mapping your remote buttons to keypresses.

First of all a script is needed that can send keystrokes. AppleScript is the most logical candidate. A script like the following should do the trick (note: at the end of this posting you can find a link to download a full version of this script):
-- Filename: keystroke-simple.applescript
-- Author:   Edwin Woudt
-- Version:  20090407-1
--
-- Note:     This is a simplified version of the full script.
--           Download keystroke.applescript below for the full version.
 
on run argv
    
    set xkey to (item 1 of argv)
    
    if ((count of argv) > 1) then
        set xmod to (item 2 of argv)
    else
        set xmod to ""
    end if
    
    set xcode to 0
    if xkey = "down" then set xcode to 125
    if xkey = "up" then set xcode to 126
    
    if xmod = "" then
        if xcode = 0 then
            tell application "System Events" to keystroke xkey
        else
            tell application "System Events" to key code xcode
        end if
    else
        if xcode = 0 then
            if xmod = "x" then tell application "System Events" to keystroke xkey using command down
        else
            if xmod = "x" then tell application "System Events" to key code xcode as integer using command down
        end if
    end if
    
end run

This script can be called with two command line parameters:

  1. A key, either a letter or a special key like ‘up’, ‘down’, ‘esc’ or ‘enter’
  2. An optional modifier, consisting of one or more of the following letters: ‘c’ for Control, ‘o’ for Option, ’s’ for Shift and/or ‘x’ for Command (note: the simple version only supports the ‘x’ modifier, the full version below supports all modifiers and all combinations).

This script will be called from a ‘lircrc’ file, of which the following is a small example:
# Filename: vlc-simple.lircrc
# Author:   Edwin Woudt
# Version:  20090407-1
 
#  Note:     This is a simplified version of the full file.
#           Download vlc.lirrc below for the full version.
 
# Play button
begin
    prog   = irexec
    button = Play
    config = /usr/bin/osascript ~edwin/Documents/Scripts/keystroke.applescript p x
end
 
# Volume buttons
begin
    prog   = irexec
    button = VolUp
    config = /usr/bin/osascript ~edwin/Documents/Scripts/keystroke.applescript up x
end
begin
    prog   = irexec
    button = VolDown
    config = /usr/bin/osascript ~edwin/Documents/Scripts/keystroke.applescript down x
end

This file will basically instruct lirc to output a ‘Command-P’ when I click on the Play button, ‘Command-Up Arrow’ for the volume up button and ‘Command-Down Arrow’ for the volume down button. These correspond to the default keys used by VLC, according to the VLC Preferences -> Hotkeys.

Create the file with a texteditor (or download my full version below) and run it in a terminal using:
irexec ~edwin/Documents/Scripts/vlc.lircrc

Note: all my scripts assume their location to be in the Documents/Scripts subdirectory of my home directory. Feel free to change it to a different location.

Now start up a video in VLC media player and try to use some buttons!

Download attachments:
vlc.licrc
keystroke.applescript

Next steps

You have now reached the end of this three part tutorial on getting your MCE remote control to work on your Mac. Hopefully this has all worked out for you: let me know through a comment or by mailing me at edwin AT woudt DOT nl.

A few things you could do after this tutorial:

  • change the configuration for the VLC media player to be more of your liking
  • add configuration files for other applications
  • somehow extend all this with detection of which application is running (using AppleScript?) and change the behaviour of the remote based on that
  • use a different linux distribution
  • use VirtualBox as a free alternative to Parallels

If I get around to one of these things, I will post the results on this blog. Of course: should you have anything to add, let me know, whether it is a solution to one of the above suggestions, or a completely different thing.

  1. dven says:

    thank you very much!
    everything works fine

  2. jules says:

    great tips! after a long night I finally got it working on my mac mini as well – had a few problems with doing it your way though… I think the most recent build of finnix has changed a few things since you wrote your instructions, I couldn’t get the headers, some of your other instructions threw errors at me, and my linux skills are pretty weak in terms of sorting that out. In the end (following some advice from a friend who knows more about linux than me) went with ubuntu server edition. All good… got it working and the MCE remote lets me do some cool stuff courtesy of applescript (eg switch between plex and eyeTV etc at will). I’ve yet to figure out a way of mapping different functions to the buttons depending on which app you’re running but I’m sure I’ll get there in the end… the only thing I would say is that ubuntu is clearly a bit heavier than finnix, there’s something of a delay between hitting a button and plex responding – maybe 0.3-0.5 seconds – not a lot but enough to be a bit annoying. I’ll try some tweaks to speed things up sooner or later… either way it’s a big improvement! Thank you for the ideas!

  1. There are no trackbacks for this post yet.