I spent a bit of this morning messing around with an Alfred workflow for MC. My first goal was this:
Assign a keyboard shortcut that would lock my screen and pause MC if it was playing.
Alfred makes hotkey assignment easy. It also knows how to lock the screen, so that part was easy. A super duper easy little Alfred workflow (my first one I've ever done) and that worked. But how to Pause MC? I tried AppleScript and it was mostly a no go. Sending specific control keys to MC *did* work via AppleScript. But it wasn't all that pretty.
Then I remember MCWS, the web based REST API that controls most of what MC can do (not everything, but it does a lot). I was quickly able to find and test Stop, Play, and Pause. It took some experimentation, but I found combinations of commands that would Play if stopped OR toggle pause if stopped. Also found how to do a pure Pause. It pauses if music is playing. But does nothing if music is NOT playing. This is important because if I invoke a pause toggle when locking the screen, it might turn music ON instead of OFF. A pure pause prevents it from turning it ON ever. It only pauses.
I wrote some tiny little shell scripts to call MCWS commands with curl (command line web utility that's standard in Mac OS (and many other OSes)). They worked as expected.
Then I added the pure pause to my lock workflow. It works!! Now when I press Command-L, the music stops and my screen instantly goes to screen lock.
I've never really liked media keys for music control because they aren't in places that are intuitive for me to reach. So I decided to try a Pause Toggle on a key I could easily remember and reach. Made a tiny Alfred Workflow for that and *boom* I have a global keyboard shortcut for MC play/pause. Did another one for next track. That works great too.
I don't think anyone is really very interested in this, but I'd share more details on the off chance that someone wanted to do something similar.
Brian.