1

I do one screenshot per minute using next bash script

while true;
do
    scrot -d 60 -q 1 '%Y-%m-%d-%H:%M:%S.png' -e 'mkdir -p ~/screen-snapshots/%Y-%m-%d & mv $f ~/screen-snapshots/%Y-%m-%d/';
done

But screenshots are made also if screen is locked. How to do screenshots only is screen is not locked?

System - Ubuntu 14.10 with Unity

[Solution]

Thanks for @solsTiCe. Whole script is

#!/bin/bash

function isScreenLocked() {
    gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked | grep -q false
}

while true;
do
    sleep 60;
    if isScreenLocked
    then
        scrot -q 1 '%Y-%m-%d-%H:%M:%S.png' -e 'mkdir -p ~/screen-snapshots/%Y-%m-%d; mv $f ~/screen-snapshots/%Y-%m-%d/';
    fi
done
Nawa
  • 113

1 Answers1

2

you can use gdbus to check for unity locked property.

gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked

So in bash you can make a function like this

function IsScreenLocked() {
    gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked|grep -q true
}
solsTiCe
  • 9,515