There are a bunch of tools that allow you to lock your desktop
automatically (gnome-screensaver or xscreensaver for example), and
several scripts and tools to handle locking and unlocking using
bluetooth proximity, etc. One thing that always drove me crazy is that
there are so many places you have to set yourself away. IRC, your IM
client, and others require you to put in your AFK message. What about
sound? If I'm using speakers, I don't want my music/notifications going
off while I'm gone and irritate people in the office, so that needs to
be muted. What about a timestamp? If I set my AFK message to be
"Lunchtime, back in an hour", how does the other person know when I'll
be back? Enter lockit. It's rather hackish at the moment, but I think
you'll get the idea quickly and can add your own pieces.
You will notice there is some remote-access code in here. If you have
multiple systems and use synergy to tie them together, making sure they
all lock/unlock together is useful. This script has the ability to log
on remotely and call lock-command from there.
Some ideas I've had are modules, miniscripts that get called much like
the initscripts rc*.d directories. Call them with "lock" when it locks,
and "unlock" when it unlocks, etc. I think that would make it modular
enough and allow other languages to handle some of the work.
lockit is two scripts. 'lockit' itself just sets the AFK message and
calls lock-command. lock-command does the heavy lifting, setting the AFK
message for all commands.
How to use: run
lockit My Message
This will currently:
Set you away in xchat
Set your away message to: "AFK, left at 07:44 EDT : My Message"
Mute your pulseaudio sink (mutes all audio)
Set your pidgin away message to "AFK, left at 07:44 EDT : My
Message"
It then goes into a monitor loop, waiting for the screensaver to unlock.
When it unlocks, it sets you back in xchat and pidgin, then unmutes your
audio.
#!/bin/bash# Automates lock-unlock of screen using lock-command# 2009-8-24# Richard Monk (rmonk@redhat.com)## secsToClockTime is a standard function to convert seconds to HH:MM:SSfunction secsToClockTime {local hoursPart
local minsPart
local secsPart
if[ -z "$1"];thenreturn1elsesecs="$1"fihours="$(($secs/3600))"secs="$(($secs%3600))"mins="$(($secs/60))"secs="$(($secs%60))"if["$hours" -gt 0];thenhoursPart="$hours"fiif["$mins" -gt 0];thenminsPart=":$(printf'%02i'$mins)"fisecsPart=":$(printf'%02i'$secs)"echo"${hoursPart}${minsPart}${secsPart}"return0}# Get message if none on the command lineif[ -z "$*"];thenawayMessage="$(zenity --entry --title="Lockit" --text="Away Message")"elseawayMessage="$@"fi#Record lock timelockTime="$(date +%s)"# Lock the screen
lock-command lock "$awayMessage"# Wait for gnome-screensaver to disengagewhile gnome-screensaver-command -q | grep -q '\';do
sleep 1done#response="$(xscreensaver-command -time)"#echo "$(date): $response" >> /tmp/lockit.out#while echo "$response" | grep -q 'locked'; do# sleep 1# response="$(xscreensaver-command -time)"# echo "$(date): $response" >> /tmp/lockit.out#done
lock-command unlock
# How long were we locked? lockClock="$(secsToClockTime $(echo$(date +%s) - $lockTime| bc))"
notify-send -t 2000"Lockit: Gone for $lockClock"echo"Lockit: Gone for $lockClock"#!/bin/bash# Set master to true if you want it to go to the hosts in $hostsmaster="false"hosts="remote.host.com"# What hour does your shift start/end (afk vs gone messages)shiftStart="7"shiftEnd="4"PATH="${PATH}:${HOME}/bin"# This pulls the session info from metacity. If you use another window manager, set it in termPidfunction getEnviron {termPid=$(pgrep metacity)cd /proc/$termPid$(cat /proc/$termPid/environ | tr '\000''\n'| sed 's/^/export /'| egrep 'DISPLAY|DBUS_SESSION_BUS_ADDRESS|SESSION_MANAGER')}# Sends commands to all xchat connected serversfunction xchat-allserv {if pgrep xchat &> /dev/null;then
xchat-command allserv $@fi}case"$1" in
lock)if["$master"=="true"];thenecho"Locking $host"for host in $hosts;do
ssh $host bin/lock-command lock
doneelseif[ -n "$SSH_CONNECTION"];then
getEnviron
fifishiftmessage="AFK, left at $(date +'%H:%M %Z') : $@"
gnome-screensaver-command -a
#xscreensaver-command -lock
pgrep pidgin &> /dev/null && purple-remote 'setstatus?status=away&message='"$message"# amixer set 'Master',0 "mute" &> /dev/null# Get pulse sinkpasink="$(pactl stat | grep 'Default Sink'| cut -d: -f2)"
pactl set-sink-mute $pasink1
xchat-allserv away "$message"#xset dpms force off;;
unlock)if["$master"=="true"];thenecho"Unlocking $host"for host in $hosts;do
ssh $host bin/lock-command unlock
doneelseif[ -n "$SSH_CONNECTION"];then
getEnviron
fifi
gnome-screensaver-command -d
purple-remote 'setstatus?status=available&message='#amixer set 'Master',0 "unmute" &> /dev/nullpasink="$(pactl stat | grep 'Default Sink'| cut -d: -f2)"
pactl set-sink-mute $pasink0
xchat-allserv back
xset dpms force on
;;esac