Extended mode with bash script
Hi,
i tried use scriptable-notifications with bash ;)
- extended mode
- connectionless
#!/bin/bash
# read stdin from stdin (skip first 4 bytes)
readarray -t meta < <( tail -c+5 | jq '.message.author, .message.subject, .message.folder.name, .message.read'| sed -r "s/\"|<|>//g")
from=${meta[0]}
subject=${meta[1]}
folder=${meta[2]}
readed=${meta[3]}
# skip if already readed
if [[ "xxx$readed" == "xxxtrue" ]]; then
exit;
fi
msg="${folder}\nFrom: ${from}\nSubject: ${subject}"
#send to tg
tgsend -t 'mytoken' --chatId='mychatid' -m "$msg"
i see few procceses like this
anton 3060469 3059986 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060470 3060469 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060577 3059986 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060578 3060577 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060747 3059986 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060748 3060747 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060795 3059986 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15} anton 3060796 3060795 0 10:13 ? 00:00:00 /bin/bash /home/anton/bin/thunderbid-notify/notify.sh /home/anton/.mozilla/native-messaging-hosts/scriptableNotifications.json {271e72b1-166c-471b-bc06-41e03f176b15}
but messages to tg not sending..
if connecting to this any process with strace, i see wait/read syscall
[anton@dell thunderbid-notify]$ sudo strace -p 3060796
strace: Process 3077447 attached
wait4(-1,
^Cstrace: Process 3077447 detached
<detached ...>
[anton@dell thunderbid-notify]$ sudo strace -f -p 3060747
strace: Process 3077445 attached
read(0,
[anton@dell thunderbid-notify]$ cat /tmp/tb-notify-Lyyod | tail -c+5 | jq
{
"accounts": {
"account1": {
"identities": [
{
"email": "[email protected]",
"label": "",
"name": "Anton Shevtsov",
"organization": "Base"
}
],
"name": "[email protected]",
"type": "imap"
},
"account22": {
"identities": [],
"name": "RSS",
"type": "rss"
},
"account2": {
"identities": [],
"name": "Local folders",
"type": "none"
}
},
"folders": [
{
"accountId": "account1",
"favorite": true,
"name": "Inbox",
"path": "/INBOX",
"totalMessageCount": 2058,
"type": "inbox",
"unreadMessageCount": 1,
"seenMessageCount": 0
},
{
"accountId": "account1",
"favorite": true,
"name": "redmine",
"path": "/redmine",
"totalMessageCount": 12607,
"unreadMessageCount": 0,
"seenMessageCount": 0
}
],
"event": "read",
"message": {
"author": "Anton Shevtsov <[email protected]>",
"ccList": [],
"date": "2025-01-09T11:10:29.000Z",
"flagged": false,
"messageId": "CAH92KP2mZEbn1pg8OEP4-ArDOoMFnKSv5RrJypQmWQQtXH9fsw@mail.gmail.com",
"headersOnly": false,
"junk": false,
"junkScore": 0,
"read": false,
"size": 3330,
"subject": "qwe",
"tags": [],
"folder": {
"accountId": "account1",
"name": "Inbox",
"path": "/INBOX",
"type": "inbox"
}
}
}
[anton@dell thunderbid-notify]$ cat /tmp/tb-notify-Lyyod | hexdump -C | head -2
00000000 1f 04 00 00 7b 22 61 63 63 6f 75 6e 74 73 22 3a |....{"accounts":|
00000010 7b 22 61 63 63 6f 75 6e 74 31 22 3a 7b 22 69 64 |{"account1":{"id|
But if start manually, all work fine
[anton@dell thunderbid-notify]$ cat /tmp/tb-notify-Lyyod | /home/anton/bin/thunderbid-notify/notify.sh
What i can do wrong?
p.s. After close thunderbird all messages will be sent to tg.
Hi,
To be honest, this is probably above my pay grade, but if it helps:
-
Have you read this: https://stackoverflow.com/a/24777120/843699
-
Maybe your bash script doesn't close the connection properly, such as: https://github.com/electrotype/thunderbird-addon-scriptable-notifications/blob/main/scriptExamples/simpleMode/linux-simple/script.sh#L52-L55
But I'll let more competent people answer you, if they can. Good luck!