Skip to content

Instantly share code, notes, and snippets.

@gnachman
Created February 9, 2020 00:55
Show Gist options
  • Save gnachman/e311939364225dfaeb9a72d0928d7977 to your computer and use it in GitHub Desktop.
Save gnachman/e311939364225dfaeb9a72d0928d7977 to your computer and use it in GitHub Desktop.
Register function to show one alert at a time
import asyncio
import iterm2
pending = False
last_coro = None
async def main(connection):
loop = asyncio.get_event_loop()
async def really_notify(message, window_id):
global pending
alert = iterm2.Alert("Hey", message, window_id)
pending = True
await alert.async_run(connection)
# Sleep for a sec so you can hit control-c for a runaway job
await asyncio.sleep(1)
pending = False
@iterm2.RPC
async def notify(message, window_id=iterm2.Reference("tab.window.id")):
if pending:
return
global last_coro
if last_coro:
await last_coro
last_coro = loop.create_task(really_notify(message, window_id))
await notify.async_register(connection)
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment