diff --git a/bin/waybar_mail.py b/bin/waybar_mail.py
new file mode 100755
index 0000000..262d829
--- /dev/null
+++ b/bin/waybar_mail.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+import json
+import subprocess
+import re
+
+ACCOUNTS = ["posteo", "gmail", "xkonni"]
+l_acc = max([len(a) for a in ACCOUNTS])
+SERVICES = ["mbsync@ykonni", "muchsync@ykonni"]
+l_ser = max([len(s) for s in SERVICES])
+
+tooltip="accounts\n"
+total = 0
+
+for a in ACCOUNTS:
+ cmd = f"notmuch count folder:{a}/Inbox AND tag:unread AND NOT tag:killed"
+ ret = subprocess.check_output(cmd, shell=True).decode("UTF-8").replace("\n", "")
+ count = int(ret)
+ tooltip += f" - {a:<{l_acc}}: {count}\n"
+ total += count
+
+tooltip += "\nservices\n"
+for s_name in SERVICES:
+ cmd = f"/usr/bin/systemctl --user status {s_name}"
+ ret = ""
+ s_status = ""
+ s_time = ""
+ try:
+ ret = subprocess.run(cmd, capture_output=True, check=False, shell=True)
+ except Exception as ex:
+ print(ex)
+ pass
+
+ s_status = 0
+ for line in ret.stdout.decode("UTF-8").split("\n"):
+ if "since" in line:
+ m = re.search("[a-z0-9 ]* ago", line)
+ if m:
+ s_time = m.group(0)
+ if ("Process" in line) or ("Main PID" in line):
+ m = re.search("status=[0-9]*", line)
+ if m:
+ tmp = int(m.group(0).replace("status=", ""))
+ if not tmp == 0 and not tmp == s_status:
+ s_status = tmp
+
+ tooltip += f" - {s_name:<{l_ser}}: status={s_status}, {s_time}\n"
+
+text = f"{total}"
+alt = "read" if total == 0 else "unread"
+
+j = { "alt": alt, "class": "mail",
+ "text": text, "tooltip": tooltip }
+print(json.dumps(j))
+
diff --git a/bin/waybar_mail.sh b/bin/waybar_mail.sh
deleted file mode 100755
index 93b3491..0000000
--- a/bin/waybar_mail.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash
-
-MAILDIR=$HOME/.mail
-ACCOUNTS=(posteo gmail xkonni)
-SERVICES=(mbsync@ykonni muchsync@ykonni)
-
-
-text=""
-tooltip="accounts\n"
-total=0
-for acc in ${ACCOUNTS[@]}; do
- count=$(notmuch count folder:$acc/Inbox AND tag:unread AND NOT tag:killed)
- total=$((total+count))
- tooltip+=" - $acc: $count\n"
-done
-
-tooltip+="\nservices\n"
-for service in ${SERVICES[@]}; do
- tooltip+=" - $service:\n$(systemctl --user status $service | grep -e 'Active' | sed 's/Active:[ ]*//g')\n"
-done
-
-
-alt=$( [ $total -gt 0 ] && echo "unread" || echo "read" )
-text="$total"
-json="{\"text\": \"$text\", \"tooltip\": \"$tooltip\", \"class\": \"mail\", \"alt\": \"$alt\"}"
-echo $json
diff --git a/waybar.d/config b/waybar.d/config
index a698daf..7b18684 100644
--- a/waybar.d/config
+++ b/waybar.d/config
@@ -89,7 +89,7 @@
"read": " "
},
"escape": true,
- "exec": "$HOME/.config/sway/bin/waybar_mail.sh 2> /dev/null"
+ "exec": "$HOME/.config/sway/bin/waybar_mail.py 2> /dev/null"
},
"custom/media": {
"format": "{icon} {}",
diff --git a/waybar.d/config_annoyance b/waybar.d/config_annoyance
index a9ee1ca..d305098 100644
--- a/waybar.d/config_annoyance
+++ b/waybar.d/config_annoyance
@@ -86,7 +86,7 @@
"read": " "
},
"escape": true,
- "exec": "$HOME/.config/sway/bin/waybar_mail.sh 2> /dev/null"
+ "exec": "$HOME/.config/sway/bin/waybar_mail.py 2> /dev/null"
},
"custom/media": {
"format": "{icon} {}",