Add scripts for binding the Mac media keys to control either cmus or mpd
This commit is contained in:
parent
eb8fe225bd
commit
817fde420e
3 changed files with 80 additions and 0 deletions
16
Library/LaunchAgents/me.00dani.mediakeys-mpd.plist
Normal file
16
Library/LaunchAgents/me.00dani.mediakeys-mpd.plist
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>me.00dani.mediakeys-mpd</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>zsh</string>
|
||||
<string>-lc</string>
|
||||
<string>mediakeys-mpd</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
32
local/bin/mediakeys-cmus
Executable file
32
local/bin/mediakeys-cmus
Executable file
|
@ -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()
|
32
local/bin/mediakeys-mpd
Executable file
32
local/bin/mediakeys-mpd
Executable file
|
@ -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()
|
Loading…
Reference in a new issue