[TASK] Init

This commit is contained in:
Philipp Dieter 2025-09-17 11:37:51 +02:00
commit c6be14bd0c
2 changed files with 78 additions and 0 deletions

26
README.md Normal file
View File

@ -0,0 +1,26 @@
# remotenotify
A small script which forwards dbus notifications from one bus to an other
# why?
I needed a way to forward messages from a chat application running on an other machine to my main machine.
# how?
Based on snippets from:
- https://stackoverflow.com/a/75122112
- https://pychao.com/2021/03/01/sending-desktop-notification-in-linux-with-python-with-d-bus-directly/
# config
In order to work the local bus must be available on the remote machine. Only do this if you trust the remote machine! In my case it is only a second workstation used exclusively by me.
```
ssh -R /run/user/1000/bus-remote:/run/user/1000/bus $REMOTEMACHINE python app.py
```
# licence
I don't think I am allowed to give this script a licence as it is basically snippets from the two pages copied together. If you want to use the code refer to the licences of the original posts.

52
app.py Normal file
View File

@ -0,0 +1,52 @@
#import dbus
#bus_local = dbus.bus.BusConnection('unix:path=/run/user/1000/bus')
#bus_remote = dbus.bus.BusConnection('unix:path=/run/user/1000/bus-remote')
# https://stackoverflow.com/a/75122112
# https://pychao.com/2021/03/01/sending-desktop-notification-in-linux-with-python-with-d-bus-directly/
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
from pprint import pprint
def msg_cb(bus, msg):
if msg.get_interface() == 'org.freedesktop.Notifications' and msg.get_member() == 'Notify':
args = msg.get_args_list()
print("Notification from '%s'" % args[0])
print("Summary: %s" % args[3])
print("Body: %s" % args[4])
bus_remote = dbus.bus.BusConnection('unix:path=/run/user/1000/bus-remote')
item = "org.freedesktop.Notifications"
notfy_intf = dbus.Interface(
bus_remote.get_object(item, "/"+item.replace(".", "/")), item)
notfy_intf.Notify(
args[0], 0, "", args[3], args[4],
[], {"urgency": 1}, -1)
def main():
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj_dbus = bus.get_object('org.freedesktop.DBus',
'/org/freedesktop/DBus')
obj_dbus.BecomeMonitor(["interface='org.freedesktop.Notifications'"],
dbus.UInt32(0),
interface='org.freedesktop.Notifications')
bus.add_message_filter(msg_cb)
print('start')
mainloop = GLib.MainLoop()
mainloop.run()
if __name__ == '__main__':
main()