Note: these instructions apply to OS X only. I’m not sure how you’d accomplish something similar on a regular Linux distro.

I got a Leap Motion recently, and wanted to use it with my MacBook. It’s pretty cool tech, and communicates with apps by running a WebSockets server daemon on startup. I’ve been working on plugging into this WebSockets server for a Cylon module, actually.

Unfortunately, even if I’m not using the Leap Motion, this server is still running, and still using up battery power. I try to make sure my laptop’s battery life is good, but I still want to be able to hack on the Leap Motion from time to time. So we need to kill the daemon, along with the Leap Motion app it runs at startup. We still want to be able to run them manually, though.

First, let’s stop the currently running leapd daemon instance:

sudo launchctl unload /Library/LaunchDaemons/com.leapmotion.leapd.plist

Now that we’ve gotten rid of that, let’s remove it and the LaunchAgent that starts Leap Motion.app on startup:

sudo rm -rf /Library/LaunchDaemons/com.leapmotion.leapd.plist
sudo rm -rf /Library/LaunchAgents/com.leapmotion.Leap-Motion.plist

Now that we’ve got those out of the way, Leap Motion will not work if we plug it in, and won’t work on startup. Now we need to manually start the Leap Motion app and leapd server if we want to use the Leap Motion. We can make a couple quick shell functions to make starting up and tearing down this arrangement easier:

function leap-up() {
    (sleep 1 && open /Applications/Leap\ Motion.app)&
    /Applications/Leap\ Motion.app/Contents/MacOS/leapd
}

function leap-down() {
    killall leapd
    killall Leap\ Motion
}

Now if we run the leap-up function in the shell, we get output like this:

$ leap-up
[2] 3088
[2]  + done       ( sleep 1 && open /Applications/Leap\ Motion.app; )
[19:37:25] [Info] WebSocket server started

And now leapd is running in the foreground, and will continue to do so until we close it or run the leap-down command.