Skip to content

Instantly share code, notes, and snippets.

@jdvala
Last active May 6, 2021 06:39
Show Gist options
  • Save jdvala/d5922aef743f095128a358ad84a968f0 to your computer and use it in GitHub Desktop.
Save jdvala/d5922aef743f095128a358ad84a968f0 to your computer and use it in GitHub Desktop.
commands to keep you sit straight

The script below will allow you to run gui programs from crontab

usage: * * * * /path/to/belowcode.sh "gui application"
#!/bin/bash                                                                                                                                                                                                                                

# Check whether the user is logged in Mate
while [ -z "$(pgrep gnome-session -n -U $UID)" ]; do
       sleep 3 && count=$((count+1)) && echo "$count" > /tmp/gnome-cron.log
done

# Get the content of the Current-Desktop-Session Environment File as an array:
EnvVarList=`cat -e "/proc/$(pgrep gnome-session -n -U $UID)/environ" | sed 's/\^@/\n/g'`

# Export the Current-Desktop-Session Environment Variables:
for EnvVar in $EnvVarList; do
       echo "$EnvVar" >> /tmp/gnome-cron.log
       export "$EnvVar"
done

# Execute the list of the input commands
nohup "${1}" >/dev/null 2>&1 &

exit 0

then crontab -e

* * * * /home/user/run_gui_cron.sh "/usr/bin/zenity --info --text='Sit Straight'"
*/30 * * * /home/user/run_gui_cron.sh "/usr/bin/zenity --info --text='Drink water'"

Ref: https://askubuntu.com/questions/978382/how-can-i-show-notify-send-messages-triggered-by-crontab/978413#978413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment