Notify-send not running on startup ( when using startup manager )

72 Views Asked by At

I'm trying to run the following script at startup. The script works fine, the only thing is that the notification doesn't work. I will be able to see the notification only when I execute the script from the terminal, or when I run it as a program. So the issue is basically when run by the Startup Manager.

Script:

#!/bin/bash

// This was suggested in a post on stackoverflow, but still not doing nothing.
export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/${UID}/bus}"

# Error log file
ERROR_LOG_FILE="$HOME/onedrive_mount_error_log.txt"

# Delay to ensure the system and services are fully up
sleep 120  # Increased delay

# Explicitly set DBUS_SESSION_BUS_ADDRESS for notify-send in a startup environment
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
export DBUS_SESSION_BUS_ADDRESS

# Log the current environment variables (for debugging)
env >> "$HOME/script_env_log.txt"

# Check if rclone is installed
if ! command -v rclone &> /dev/null; then
    echo "rclone not found. Exiting script." >> $ERROR_LOG_FILE
    exit 1
fi

# Mount OneDrive using rclone
if rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive; then
    # If mount is successful, send a notification
    /usr/bin/notify-send "OneDrive Connected" "Microsoft OneDrive successfully mounted."
else
    # If mount fails, log the error
    echo "Failed to mount OneDrive on $(date)" >> $ERROR_LOG_FILE
    /usr/bin/notify-send "OneDrive Connection Failed" "Rclone failed to mount OneDrive."
fi

This is my Startup Manager command: enter image description here

I'm using Ubuntu 23.10

This was suggested in a post on stackoverflow, but still not doing nothing. export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/${UID}/bus}"

Also I tried to run the script from terminal or by making it executable and running it as a program. In both scenarios I can see the notification. Only at startup it doesn't work.

1

There are 1 best solutions below

0
Code learner On

On some systems, the below script works. You can try adding the

export XDG_RUNTIME_DIR=/run/user/$(id -u)

Sample bash script :

#! /bin/bash
export XDG_RUNTIME_DIR=/run/user/$(id -u)
set -x 
notify-send "Hello"