Get Notifications On Your Desktop Or Phone When A Long-Running Command Has Finished With Noti

Noti long-running command has finished notification desktop mobile

Ever wanted to get notified when a long-running process / command has finished, not only on your desktop but also on your phone? Noti can do that.

Noti is a command line tool for macOS, Linux and Microsoft Windows that monitors a process / command, and triggers a notification on your desktop or phone when it has finished running.

Supported notifications:

  • Desktop notifications (banners)
  • Speech
  • BearyChat
  • Keybase
  • Mattermost
  • Pushbullet
  • Pushover
  • Pushsafer
  • Simplepush
  • Slack
  • Telegram
  • Zulip
  • Twilio

All of these supported notifications work on macOS, Linux and Windows.

It's worth noting that if all you want is to receive a desktop notification when a long-running command has finished on Linux, you can simply run command; notify-send Done (e.g. sleep 3; notify-send Done).

By default, Noti only shows the text "Done!" when a long-running task is done, but this can be extended. You can specify the notification title (default is utility name), set the notification message (default is "Done!"; read from stdin with -), and show the execution time in the notification message.

You can use Noti in the beginning of a command, e.g.:

noti sleep 3

And after a command, e.g.:

sleep 3; noti

You can even use Noti after a command was already started, either by getting the process PID, then using the following command:

noti --pwatch PID

Or by pressing Ctrl + z after a process was started to temporarily suspend it, then resume it with:

fg; noti

For more on Noti, including how to set up Noti notifications with various services, Noti environment variables, etc. see this page. While testing this though, I noticed that this page is somewhat out of date. For example, Slack no longer allows creating legacy tester tokens. So you may also want to check out the Noti man page from here, and noti.yaml man from here.

Read on for how to install and configure Noti, including complete instructions for setting up Noti to notify on your mobile device via Telegram and Slack when a long-running command has finished.

You might also like: How To Repeat A Command Every X Seconds On Linux


Installing and configuring Noti



The Noti installation instructions linked using the button above contain multiple ways of installing this tool. If you want to grab the binary directly, simply head over to the tool's GitHub releases page.

The easiest way of installing Noti on Linux is to download the binary from the releases page, extract the archive, then install the noti binary to /usr/local/bin using (assuming you've extracted the Noti binary archive in your home folder, and you open the terminal in your home directory):

sudo install noti*linux-amd64/noti /usr/local/bin

By default, Noti uses desktop notifications (banners). Below I'll show you how to configure Noti to send notifications when a long-running process has finished, on your mobile device via Slack and Telegram, since that's what I use. If you want to use it with another service you'll need to configure it on your own, using the instructions (albeit somewhat incomplete in my opinion, and outdated in some cases, e.g. you can no longer create Slack tokens, and you must use a Slack App) from here.

You might also like: Bit Is A Modern Git CLI With An Interactive Prompt


Configure Noti to notify you when a long-running command has finished running by sending a message on Telegram


To get Noti to send you Telegram messages when a long-running command has finished running, you'll need a Telegram chatId and token. This works with either a Telegram chat or channel. In my instructions below we'll be using a Telegram channel.

1. Create a Telegram channel.

The first thing you need to do is create a Telegram channel. It can have any name and description you want.

2. Create a Telegram bot and get the HTTP API access token.

Next, you need use BotFather (@botfather) to create a bot and get an HTTP API access token.

To do this, start a chat with @botfather, and type /start in the chat to see the available commands, etc. Now type /newbot to create a new bot, and follow the instructions (you'll need to set a name and a username for your new bot). When you're done, @botfather will show a token to access the HTTP API. Copy this token because we'll need it later.

3. Add the Telegram bot created in step 2 to your channel and get the chatId.

Now we have a token, but we also need to get the chatId.

Add the bot you've created under step 2 to your new Telegram channel (go to the channel, and from the options choose Add users and search for the bot you've created).

Once the bot has been added, type a message in your Telegram channel. This is important and required in order to get the chatId.

Now you can get the chatId by visiting the following link which you'll have to edit:

https://api.telegram.org/botXXX:YYYYY/getUpdates

Replace XXX:YYYYY with your bot's HTTP API token that you got under step 2.

This link will show a bunch of text among which you'll find:

chat":{"id":-100999999999}

The id from here is your chatId that you need to use with Noti. That - sign at the beginning of the number is part of the chatId, so make sure you use that too, and not just the numbers.

4. Create the Noti configuration file (if you haven't created it already) and add Telegram to it.

Now that we know the Telegram chatId and HTTP API token, create the Noti configuration file, called noti.yaml in ~/.config/noti/

Open this file with a text editor and paste the following:

telegram:
  token: THE_HTTP_API_TOKEN_GOT_UNDER_STEP_2
  chatId: 'THE_CHAT_ID_GOT_UNDER_STEP_3'

Example (edited to not contain my real token and chatId):

telegram:
  token: 1598888700:AEEijJJcsABpYR1LdJ4_Llkr1Vq48vxAUSg
  chatId: '-10099999999999'

Test Noti sending a Telegram message when a long-running command has finished running by using:

sleep 3; noti --telegram

Don't worry, you don't need to add the --telegram command line parameter every time you use Noti. You can export NOTI_DEFAULT with a list of notification types to trigger, e.g. to use desktop banner notifications and Telegram notifications, you'd need to export NOTI_DEFAULT="banner telegram".

Add export NOTI_DEFAULT="banner telegram" to your ~/.profile file to make the change permanent. Obviously, edit the NOTI_DEFAULT notification types to what you want to use. Logout and re-login after making changes to your ~/.profile file to use the new settings.

You might also be interested in: How To Find Files Modified In The Last N Days Or Minutes Using find


Configure Noti to notify you when a long-running command has finished running by sending a message on Slack


The Noti documentation page mentions creating a OAuth Token for Testing and Development, but this is no longer supported by Slack. Instead of this, we'll need to create a Slack app.

1. Login to Slack using a web browser.

2. Create a Slack app.

Head over to https://api.slack.com/apps/new and create a new Slack app using any name you want.

3. Activate Incoming Webhooks.

After creating a Slack App, you'll be redirected to your new app's settings page. Here (having Basic Information selected on the left-hand sidebar), expand the Add features and functionality section, then click on Incoming Webhooks. Here, turn on the switch next to Activate Incoming Webhooks.

4. Create an Incoming Webhook.

At the bottom of the Incoming Webhooks page, click Add New Webhook to Workspace, and select a channel or youself (with the latter being under Direct Messages). This is where you'll receive the notification. I've selected my username here.

[[Edit]] The steps to create a Slack app and an Incoming Webhook are also explained in the Slack API documentation.

After creating an Incoming Webhook, you'll be redirected to the Incoming Webhooks page. At the bottom of this page you should see the Webhook URL. Copy this URL.

5. Create the Noti configuration file (if you haven't created it already) and add Slack to it.

Now that we've got the Slack Webhook URL, create the Noti configuration file, called noti.yaml in ~/.config/noti/

Open this file with a text editor and paste the following:

slack:
  appurl: 'https://hooks.slack.com/services/xxx/yyy/zzz'

Here, replace the appurl value with the Slack Webhook URL you've got under step 4, and save the file.

Test Noti sending a Slack notification when a long-running command has finished running by using:

sleep 3; noti --slack

To always use Slack for sending notifications when typing noti (so you don't have to type noti --slack every time you want to be notified on Slack), you can export NOTI_DEFAULT with a list of notification types to trigger, e.g. to use desktop banner notifications and Slack notifications, you'd need to export NOTI_DEFAULT="banner slack".

Add export NOTI_DEFAULT="banner slack" to your ~/.profile file to make the change permanent. Obviously, edit the NOTI_DEFAULT notification types to what you want to use. Logout and re-login after making changes to your ~/.profile file to use the new settings.

You might also like: Bash History: How To Show A Timestamp (Date / Time) When Each Command Was Executed