Photo by Lucas Benjamin on Unsplash

Control your OS X Sound Volume with Leap Motion Controller

Extend Leap Motion to do your own stuff

I just bought my Leap Motion controller from BestBuy the other day and I’ve took it for a spin. Everybody that bought the device found out pretty soon that there are only a few applications that are available at the moment and there’s not much to do with it out of the box.

I’m a fan of controllers, robots, and all the new geeky cool stuff but this one didn’t get me the excitement and control that I wanted. For 70 bucks it should do a little more. For all the people that think the same, there’s good news. It’s super extensible and easy to program trough their API.

I’ve heard that people are starting to do a lot of crazy stuff with Leap Motion, things like controlling drones with hands gestures for example sounds pretty cool to me. I didn't wanted to go that far but I thought of using the controller to do basic OS operations, like changing the volume when I perform gestures.

It turns out that this is fairly straightforward to implement because:

1. Leap Motion controller software basically spins up a WebSockets TCP server called leapd that runs on your machine.
2. You can connect to the leapd and then receive and send messages. Anybody who did a little websockets or messaging programming will find this as being a piece of cake.
3. There is this fancy library called LeapJS that wraps all interaction with the leap daemon (leapd) and exposes it via a nice JavaScript API.

If you put all these babies together with Node.js and Growl for OS notification, then you get a nice little executable app that reacts to your clockwise or counter-clockwise circles, changes the OS volume, and outputs interactions via Growl.

Here’s how it’s done:

1.The volume is set spinning up a child process and then run osascript set volume.
2. On every leap frame, check the gesture and if it’s a circle, check the direction and depending clockwise or not, increase or decrease the volume via the child process.
3. If the operation is successful, I call Growl notifications with the value of the volume.

If you want to make the file executable, you do it via:

chmod +x index.js

To make it run on at login make it an app via MacOSX Automator and the add it at Login via Mac Users&Groups.

I’m planning to do much more with this, to extend it with things like opening browsers, terminals, spotify changing tracks on swipe gestures and all the cool stuff.

For now, this is where you can find it: https://github.com/motiooon/leapsound. Use it and like it!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gabriel G Baciu

Gabriel G Baciu

Software engineer, leader, entrepreneur, lately focusing on the science of leadership and success, healthy living, and low latency software systems.