Feature: Notifications
Hi, I believe I once asked but maybe I am mistaking. So I was wondering if there is a way to get (custom?) notifications on mount / unmount? I am using the systemd service. If it is possible, I'd like to see a / some simple examples on how to configure it and I guess this would make people start using it easier.
Please check out the manual, the -c option allows you to specify a custom script that ldm invokes every time a device is mounted/unmounted. The LDM_ACTION, LDM_FS, LDM_NODE and LDM_MOUNTPOINT environment variables are defined and should be enough to generate the notification blurb.
The only problem I see is that you might need to export the DISPLAY variable for notify-send to work from within the script.
Thanks, so do I need to export it inside the script or how would you do that?
I guess something like
DISPLAY=:1 notify-send "Hello"
is enough, just make sure to export the correct display.
I have been trying different things and cannot get it going. I tried it the way you said, also setting DISPLAY=:0.0, DISPLAY=:0 and some other things but it didn't work. Do you have any idea?
Not really, make sure the script is executable and is actually executed first.
I was on holiday and am back now. Let me summarize what I tried (unsuccesfully):
I made a scriptfile and made it executable. My $DISPLAY variable said :0.0 so I was not sure and tried out DISPLAY=:0 notify-send "test", DISPLAY=:0.0 notify-send "test", for I don't know what reason DISPLAY=:1 notify-send "test" and also "plain" notify-send "test".
I edited my systemd file (the ExecStart variable) such that it is ExecStart=/usr/bin/ldm -u ${MOUNT_OWNER} -p ${BASE_MOUNTPOINT} -c /path/to/executable/scriptfile.sh
I am still not able to get the output "test" from my notification daemon... Do you see any mistakes / are you able to get notifications?
EDIT: for the record, the mounting/unmounting works just as expected!
EDIT 2: I also just tried simply putting a echo 'hello' to my scriptfile and running the execstart-command in my terminal. I don't see the output so I am wondering if the -c flag works at all. Can you use it succesfully?
There's no output at all, the file descriptors for stdin, stdout and stderr are closed before sh is invoked. Please check your syslog (journalctl or whatever) for ldm-related errors and try something like this to see if the commands are executed.
echo "Hello" > /tmp/check
Ok this worked, no error and the file was produced. But the notify-send just does not work. I went on reading and stumbled upon some posts seemingly having the same issue with udev rules. The problem seems to be the at startup missing DBUS_SESSION_BUS_ADDRESS. I read a bit and tried but I don't have too much time right know, so I just leave the - in my opinion - most helpful link here. The interesting part are the linked articles in Resources, mainly: notify-send bug and notify-send workaround.