Download events in aria2

In my previous post, I have demonstrated how to use aria2 as the default download manager on Unix/Linux and how to integrate aria2 into Conkeror. In this post, I’m going to show a simple tip that can cause aria2 to display notification when it finishes downloading. By default, aria2 provides some input arguments which are the event handlers for download hooks. Those events include --on-bt-download-complete, --on-download-complete, --on-download-error, --on-download-pause, --on-download-start, --on-download-stop. The solution is to pass a shell script to the event and use that bash script to activate notification program. For example

$ aria2c --on-download-complete="/path/to/notification/"

You can also pass the event handler command to the aria2 command for starting it as daemon or on RPC protocol. If you are using the command from my previous post, the command will look like this

$ touch /path/to/download/folder/session.txt && aria2c --enable-rpc --rpc-listen-all --save-session=/path/to/download/folder/session.txt --input-file=/path/to/download/folder/session.txt -x16 -s16 -k1M --dir=/path/to/download/folder --daemon --on-download-complete=/path/to/notification/

When aria2 finishes downloading, it will run the –on-download-complete script and pass 3 arguments, the third one is the path to the downloaded file. The content of the notification file should look similar to this

notification-command "Download complete $3"

Notification on Linux

Most Linux distros come with the standard APIs for displaying notification. To activate it, simply execute the command notify-send "message" in terminal. The content of the notification file is similar to this

notify-send "Download complete $3"

You can pass extra arguments to notify-send for specifying expiry time or notification icon.



Notification on Mac

Mac OS does not come with a shell application for activating notification. However, you can use Growl or terminal-notifier for displaying notification using Mac’s default Notification Center. terminal-notifier can be installed using Macports, ruby or homebrew

$ port install terminal-notifier
$ gem install terminal-notifier
$ brew install terminal-notifier

Next, edit the notification file like this

terminal-notifier -message "Download completed - $3" -title "Aria2"

To set the icon for the notification, you need to create an empty aria2 .app wrapper.

$ sudo mkdir -p /Applications/
$ sudo touch /Applications/
$ sudo touch /Applications/

Edit the content Info.plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Open Applications folder in Finder, view info of, drag and drop the image you want to the application icon

Alt Text

Now, back to the notification file and change it to

terminal-notifier -message "Download completed - $3" -title "Aria2" -sender "com.example.aria2"

Notification Mac