crontab中的notify-send 不能顯示通知的處理方法

在新版本的gnome-ubuntu系統中,發現crontab 中的 notify-send 不能顯示通知(某些版本的ubuntu中是可以顯示的,如Mint),但命令確實執行了,因為其中的無UI命令都執行了。當然后面Google到了具體的解決辦法,記錄如下:
  寫一個代碼引用otify-send :

 
#!/bin/bash 
# showtips
source /home/work/.bashrc
pid=$(pgrep -u work gnome-session | head -n 1)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//' )
export DBUS_SESSION_BUS_ADDRESS=$dbus
export HOME=/home/work
export DISPLAY=:0
/usr/bin/notify-send  $1 $2 $3 $4 

注意變更其中的目錄/home/work/為你實際的目錄路徑,保存為/usr/bin/showtips,賦于showtips運行權限:


sudo chmod +x /usr/bin/showtips

然后在crontab中使用showtips代替 notify-send

56-59 16 * * * DISPLAY=:0 /usr/bin/showtips -i /home/work/tips.png "提醒" "準備下班!"

經測試,通知完美顯示。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容