macOS下 给aria2 RPC添加一个下载通知

aria2 RPC 自带许多事件Hook机制,其中就有下载完成的事件 hook。

aria2 provides options to specify arbitrary command after specific event occurred. Currently following options are available: --on-bt-download-complete, --on-download-pause, --on-download-complete. --on-download-start, --on-download-error, --on-download-stop.

创建 hook 脚本

参考:

1
2
3
cd ~/.aria2/
touch download-complete-hook.sh
chmod +x download-complete-hook.sh

脚本内容添加如下:

1
2
3
4
5
6
#!/bin/sh
fname=`basename $3`
osascript <<EOF
display notification "$fname 已经下载完成!" with title "【下载完成】"
say "有个文件下载完成,请查收!"
EOF

最终效果:当下载完成会在屏幕右上角弹出一个提示框显示具体下载完成的文件名,同时中文语音播报:“有个文件下载完成,请查收!”

macOS 下aria2 提示框实例

  • 具体提示框设置可参考上面的教程。不支持设置自定义图标
  • 关于$3参数详见

aria2 passes 3 arguments to specified command when it is executed. These arguments are: GID, the number of files and file path. For HTTP, FTP, and SFTP downloads, usually the number of files is 1. BitTorrent download can contain multiple files. If number of files is more than one, file path is first one. In other words, this is the value of path key of first struct whose selected key is true in the response of aria2.getFiles() RPC method. If you want to get all file paths, consider to use JSON-RPC/XML-RPC. Please note that file path may change during download in HTTP because of redirection or Content-Disposition header.

添加 Hook 设置

在 aria2 设置文件.aria2.conf加入如下:

1
2
3
4
# BT下载完成(如有做种将包含做种,如需调用请务必确定设定完成做种条件)
on-bt-download-complete=${HOME}/.aria2/download-complete-hook.sh
# 下载完成
on-download-complete=${HOME}/.aria2/download-complete-hook.sh