How can I run a command which will not survive terminal close?

I want to send a notification in X seconds to future me, but I don't want to send the notification if I closed the terminal.

So let's say I want to send myself a notification in 10 seconds:

yourscript.sh:

#!/bin/sh
sleep 10
terminal-notifier -message "timeout" -ignoreDnD
exit;

If I run:

./yourscript.sh &

I will get what I want, but if I close my terminal (command+w) I'll still get the notification.

I know that if I'll exit the iterm application entirely (command+q) I won't get the notification, but that isn't really what I want.

Anything I can do?

I'm using Catalina (10.15.2)


  • Open a new terminal tab
  • Run your command without the trailing &
  • Switch back to the first tab and continue working

To cancel the notification just close the tab it's running in afterwards.