Long running script notifications

 · 
developer tools

Sometimes during development or maintenance, you have to run some script or code that takes a long time to complete and chances are you get distracted by something like Hacker News or looking through notes to find something interesting and the script ends without you realising.

Wouldn’t it be great to get a notification when the script is done?

I have used several tricks for this in the past, my go-to tip now is noti:

GitHub - variadico/noti: Monitor a process and trigger a notification.

You can use it in several ways. The easiest to remember is:

./long_running_script && noti

Bonus tip

If you are on a mac and don’t feel like installing an extra dependency, you can run notifications from the terminal:

osascript -e 'display notification "20 minutes" with title "Import done in: "'

Which will look like this:

System notification triggered from the terminal.

You can use this in Ruby as well like so:

# SomeController
def index
	`osascript -e 'display notification "#{params[:name]}" with title "params[:name] is: "'`
end

The above will show the value of params[:name] as a pop-up while testing a page which means you won’t have to put a binding.pry somewhere and go to your terminal.