Can I use my media keys to control MPD?

3

1

Can I make the media keys (play/pause, skip) buttons on my macbook control MPD, instead of iTunes?

Also, can I make the apple remote not open iTunes? Right now, the MPD client I'm using (theremin) can be controlled with the remote, but iTunes opens when I press a button.

Btw, I can't disable iTunes in parental controls because it needs to work on my administrator account, but its okay if the solution causes iTunes to not work.

Jeffrey Aylesworth

Posted 2009-10-28T12:05:45.933

Reputation: 2 170

Answers

1

I don't know about the Apple Remote (though I think there's a free app out there that lets you customize it) but I can help you with the media keys. I did this on an external keyboard using ControllerMate ($15) but I would imagine you could do the same with the free hotkey manager Sparkle: you need to point the key to an AppleScript that in turn runs a shell script that tells MPD what to do. This is not too difficult; I learned to write AppleScript and shell scripts just for this purpose, and it took me a couple of hours all told.

My MPD is on a different computer, and if yours is too you need to make sure that publickey authentication is disabled so you can ssh in without a password. (Alternately, I suppose you could install mpc on your Mac, but I was too timid to do that.) Install MPC on the computer with MPD (and make sure you've got the environment variables right). Then on the Mac, write and save a shell script that tells bash to ssh into your MPD machine and tell mpc to do something. For "toggle" (play/pause) this is mine:

#!/bin/bash
ssh 10.0.1.42 -l USERNAME "export MPD_HOST=10.0.1.42; mpc toggle --no-status"

For some reason I had to put MPD_HOST there. It should be trivial to write scripts for next and previous tracks; if you don't know the mpc commands check out mpc's man page.

My applescript is more complex than yours would be because it decides whether to control MPD or iTunes based on the applications I'm running. On a basic level all you need is

do shell script "path/to/yourscript.sh"

which you can save as a .scpd. It's easy in either ControllerMate or Sparkle to tie a key to an AppleScript, so you should be all set.

Enjoy!

Gabe

Posted 2009-10-28T12:05:45.933

Reputation:

Thank you very much, I've been waiting a long time for an answer :) – Jeffrey Aylesworth – 2010-01-28T00:11:40.507

0

First of all, you will have to tell iTunes not to grab the keys.

Then you use Karabiner to run a shell script when you press those keys (look up for VK_CONSUMERKEY_MUSIC_PLAY).

Step by step. 1. Install Karabiner:

brew install cask karabiner
  1. Download this file to Library/Application Support/Karabiner/private.xml

  2. Enable required items in Karabiner UI, or:

    /Applications/Karabiner.app/Contents/Library/bin/karabiner reloadxml /Applications/Karabiner.app/Contents/Library/bin/karabiner enable private.media_next /Applications/Karabiner.app/Contents/Library/bin/karabiner enable private.media_play /Applications/Karabiner.app/Contents/Library/bin/karabiner enable private.media_prev

Gotchas: - you should use absolute path in scripts - if you need to use shell built-in commands, run via bash -c 'script goes here'

phil pirozhkov

Posted 2009-10-28T12:05:45.933

Reputation: 185

0

As an update, notice that now you also can control MPD with a fork of Theremin client: https://github.com/TheStalwart/Theremin While the revived client supports media keys, it also inherits the music player interface from ye olde Theremin, giving you MPD's library and queue.

katrmr

Posted 2009-10-28T12:05:45.933

Reputation: 121