get xautolock status

A quick check of the source code of the current version, xautolock 2.2, shows that it doesn't support this feature, although it wouldn't be too hard to implement it yourself if you know a little bit about C and how to write X programs.

The reason is probably this: whenever you want to know the status of xautolock, you also know what status you would like it to be in. So, simply issue xautolock -disable if you want it to be off, and xautolock -enable in the contrary case. Note that all your other xautolock settings will not be affected by doing this.

Keeping track of the status yourself the way you suggest is also possible, but probably somewhat unreliable and error-prone.


You can use the functionality built into most media players to manage this; it works efectively with xautolock and it's lockers.

mpv and mplayer both have a screensaver options:

--stop-screensaver, --no-stop-screensaver Turns off the screensaver (or screen blanker and similar mechanisms) at startup and turns it on again on exit (default: yes). The screensaver is always re-enabled when the player is paused. This is not supported on all video outputs or platforms. Sometimes it is implemented, but does not work (happens often on GNOME). You might be able to to work this around using --heartbeat-cmd instead.

You can enable this fucntionality by including the line in your ~/.mpv/config:

stop-screensaver=yes

and enjoy uninterrupted playback of your videos.

If you are using a media player that doesn't have this basic functionality, you can use a simple wrapper to acheive the same effect:

#!/usr/bin/env bash
# wrapper to prevent screen blanking when files are played from ~/Videos

usage() {
    printf "%s\n" "Usage: ${0##*/} /path/to/file"
    exit 1
}

case $# in
    1)  if [[ $1 =~ Videos ]]; then
            xset dpms 0 0 0
            xautolock -disable
            vlc "$1"
            xautolock -enable
            xset dpms 900 900 900
        else
            usage
        fi
        ;;
    *) usage
        ;;
esac

I managed to do just what OP asked and it's all contained in my i3 configuration, bound to a shortcut (see below). So I lock my screen with Mod+o and I toggle automatic screen locking with Mod+Shift+o where notification appears that tells me either "LOCK on" or "LOCK OFF", depending on xautolock's "status". I made use of xautlock -exit to figure out whether or not it's running without having to manage the status in an extra file.

The script that takes care of toggled status just by itself looks like this

if xautolock -exit
    then (notify-send -u normal -t 100 -- 'LOCK OFF') 2> /dev/null
    else
        notify-send -u normal -t 100 -- 'LOCK on'
        xautolock -time 2 -locker 'slock' -notify 10 -notifier "notify-send -u normal -t 100 -- 'LOCKING screen ...'"
fi

Depending on where you call that script, you have to make sure xautolock -time ... runs in the background (e.g. by adding &).

From my .i3/config file:

exec --no-startup-id xautolock -time 2 -locker 'slock' -notify 10 -notifier "notify-send -u normal -t 10000 -- 'LOCKING screen'"

bindsym $mod+o exec --no-startup-id xautolock -locknow
bindsym $mod+Shift+o exec --no-startup-id "if xautolock -exit; then (notify-send -u normal -t 100 -- 'LOCK OFF') 2> /dev/null; else notify-send -u normal -t 100 -- 'LOCK on'; xautolock -time 2 -locker 'slock' -notify 10 -notifier \\"notify-send -u normal -t 100 -- 'LOCKING screen ...'\\"; fi"