Skip to content

Instantly share code, notes, and snippets.

@faniska
Last active November 21, 2017 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faniska/6d6c40470ff24c149523112f8208526a to your computer and use it in GitHub Desktop.
Save faniska/6d6c40470ff24c149523112f8208526a to your computer and use it in GitHub Desktop.
Notify and lock screen on Ubuntu Linux
#!/bin/sh
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"
/usr/bin/notify-send -i face-wink "Пятиминутка" "Сделай паузу!"
/bin/sleep 2
loginctl lock-session 3
#!/bin/sh
# get_display [USER] -- Returns $DISPLAY of USER.
# If first param is omitted, then $LOGNAME will be used.
get_display () {
who \
| grep ${1:-$LOGNAME} \
| perl -ne 'if ( m!\(\:(\d+)\)$! ) {print ":$1.0\n"; $ok = 1; last} END {exit !$ok}'
}
DISPLAY=$(get_display) || exit
export DISPLAY
/usr/bin/notify-send -i face-wink "Пятиминутка" "Сделай паузу!"
/bin/sleep 2
loginctl lock-session 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment