Skip to content
Permalink
bee7d071a7
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
40 lines (33 sloc) 1.12 KB
#!/usr/bin/env python3.7
import asyncio
import iterm2
import subprocess
from os.path import expanduser
import glob
import sys
import traceback
COMMAND = "play-sound"
LIBRARIES = [
expanduser("~/Seafile/General/Sounds/Nintendo/"),
expanduser("~/Seafile/General/Sounds/"),
"/System/Library/Sounds",
]
def locate_sound(name):
for d in LIBRARIES:
for m in glob.iglob("%s/%s.*" % (d, glob.escape(name))):
return m
for m in glob.iglob("%s/%s" % (d, glob.escape(name))):
return m
raise ValueError("no matching sound found")
# printf "\033]1337;Custom=id=%s:%s\a" "play-sound" "ding"
async def main(connection):
async with iterm2.CustomControlSequenceMonitor(connection, COMMAND, r'^.*$') as mon:
while True:
match = await mon.async_get()
try:
filename = locate_sound(match.group(0))
subprocess.run(["afplay", filename])
except:
traceback.print_tb(sys.exc_info()[2])
# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)