Saturday, December 27, 2014

Notification when command finished running on linux terminal

Often we run some command in terminal which takes a hell of a lot of time to finish. Then, we wish we could do something else while the command runs but get a notification when it's done.

Getting this notification is quite easy.

Just run your command in the following manner to achieve this:
your-main-command; notification-command &


where,
    your-main-command ==> the command that you are running
    notification-command ==> command used for notifying

Various Notification Commands

You can use any of these commands for notification: 

notify-send "Command finished running." #use on Ubuntu/Mint
xmessage "Command finished running." #can be used on all Linux distros


So, your final command should look something like this:
your-command; notify-send "Command finished running." &


Automating for every command


Now, what if you wanted the notification to show up after every command you type, without having to type the notification as well. To do this, install autokey first.
sudo apt-get install autokey-gtk

Autokey is a software for mapping different actions to different keystrokes. It's very powerful. Now, open Autokey and follow these steps:

  1. Here, define a new "phrase". Give it some name. In the big text-box on the right side, enter the following text:
    ; notify-send "Job finished!" &
    
    
    
    IMP: Note that in the above phrase text, there is a newline after the first line. Be sure to include that.
  2. Set the "hotkey" as alt+center.
  3. Assign the "Window Filter" as
    .*(guake)|(Terminal).*
    NOTE: If you're some other terminal than Terminal or guake, then add its name in the window filter.
You're done now. Everytime you enter a command and wish to get a notification for it, just run it using Alt+Enter and it will notify you.



No comments:

Post a Comment