From 817fde420e2d40c8ddd8036e4712f431b6ba569b Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Wed, 16 Aug 2017 10:01:48 +1000 Subject: [PATCH] Add scripts for binding the Mac media keys to control either cmus or mpd --- .../me.00dani.mediakeys-mpd.plist | 16 ++++++++++ local/bin/mediakeys-cmus | 32 +++++++++++++++++++ local/bin/mediakeys-mpd | 32 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 Library/LaunchAgents/me.00dani.mediakeys-mpd.plist create mode 100755 local/bin/mediakeys-cmus create mode 100755 local/bin/mediakeys-mpd diff --git a/Library/LaunchAgents/me.00dani.mediakeys-mpd.plist b/Library/LaunchAgents/me.00dani.mediakeys-mpd.plist new file mode 100644 index 0000000..de30aaa --- /dev/null +++ b/Library/LaunchAgents/me.00dani.mediakeys-mpd.plist @@ -0,0 +1,16 @@ + + + + + Label + me.00dani.mediakeys-mpd + ProgramArguments + + zsh + -lc + mediakeys-mpd + + RunAtLoad + + + diff --git a/local/bin/mediakeys-cmus b/local/bin/mediakeys-cmus new file mode 100755 index 0000000..6354ee7 --- /dev/null +++ b/local/bin/mediakeys-cmus @@ -0,0 +1,32 @@ +#!/usr/bin/env python +import osxmmkeys +import subprocess +import time + +commands = { + 'play_pause': '-u', + 'next_track': '-n', + 'prev_track': '-r' +} + +class CmusKeys(): + def __init__(self): + def cmusRemote(command, flag): + def f(): + print(command) + subprocess.call(['cmus-remote', flag]) + return False + return f + + self.tap = osxmmkeys.Tap() + for command, flag in commands.items(): + self.tap.on(command, cmusRemote(command, flag)) + + def run(self): + self.tap.start() + try: + while True: time.sleep(1) + except (KeyboardInterrupt, SystemExit): + self.tap.stop() + +if __name__ == '__main__': CmusKeys().run() diff --git a/local/bin/mediakeys-mpd b/local/bin/mediakeys-mpd new file mode 100755 index 0000000..8e800dc --- /dev/null +++ b/local/bin/mediakeys-mpd @@ -0,0 +1,32 @@ +#!/usr/bin/env python +import osxmmkeys +import subprocess +import time + +commands = { + 'play_pause': 'toggle', + 'next_track': 'next', + 'prev_track': 'cdprev' +} + +class MpdKeys(): + def __init__(self): + def mpdRemote(command, flag): + def f(): + print(command) + subprocess.call(['mpc', flag]) + return False + return f + + self.tap = osxmmkeys.Tap() + for command, flag in commands.items(): + self.tap.on(command, mpdRemote(command, flag)) + + def run(self): + self.tap.start() + try: + while True: time.sleep(1) + except (KeyboardInterrupt, SystemExit): + self.tap.stop() + +if __name__ == '__main__': MpdKeys().run()