-
-
Save adamv/b2a0aee9ac04229a4b93a0c09999f27c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# kill the media key program on exit | |
trap 'kill $(jobs -p)' EXIT | |
# prevent iTunes from capturing media keys | |
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2>/dev/null | |
# launch the media key program in the background | |
(cmus-media-keys) & | |
# pipe CoreAudio messages to null: | |
# https://github.com/cmus/cmus/issues/421 | |
$(brew --prefix cmus)/bin/cmus "$@" 2>/dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Use the system Python, as it has the Objective-C bridge | |
# Derived from: https://gist.github.com/drslump/2870240 | |
import subprocess | |
from AppKit import NSApplication, NSSystemDefined, NSApplicationActivationPolicyProhibited | |
from PyObjCTools import AppHelper | |
KEY_UP = 11 | |
class KeySocketApp(NSApplication): | |
repeated = False | |
def sendEvent_(self, event): | |
if event.type() == NSSystemDefined and event.subtype() == 8: | |
data = event.data1() | |
keyCode = (data & 0xFFFF0000) >> 16 | |
keyFlags = (data & 0x0000FFFF) | |
keyState = (keyFlags & 0xFF00) >> 8 | |
keyRepeat = keyFlags & 0x1 | |
if keyRepeat and keyState != KEY_UP: | |
if keyCode == 20: | |
self.repeated = True | |
# print "prev" | |
subprocess.call(['cmus-remote', '-k', '-10']) | |
elif keyCode == 19: | |
self.repeated = True | |
# print "forward" | |
subprocess.call(['cmus-remote', '-k', '+10']) | |
if keyState == KEY_UP: | |
if self.repeated: | |
self.repeated = False | |
elif keyCode == 20: | |
# print "PREV" | |
subprocess.call(['cmus-remote', '-r']) | |
elif keyCode == 16: | |
# print "PLAY" | |
subprocess.call(['cmus-remote', '-u']) | |
elif keyCode == 19: | |
# print "FORWARD" | |
subprocess.call(['cmus-remote', '-n']) | |
if __name__ == '__main__': | |
app = KeySocketApp.sharedApplication() | |
# prevent dock icon | |
app.setActivationPolicy_(NSApplicationActivationPolicyProhibited) | |
AppHelper.runEventLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment