ImageMagick - Take screenshot of the entire screen forever

By xngo on June 2, 2019

The script below will take screenshot of the entire screen forever using ImageMagick. It is useful when you also need to capture your mouse actions(e.g. mouse hover on options, mouse click on options, etc)

#!/bin/bash
set -e
# Description: Take screenshots of the entire screen on every second forever.
#    Useful when you also need to click on UI.
# -q or -s is optional. They are used to disable the beep sound when screenshot is taken.
 
no_beep=$1
 
while true; do
    # Wait for 1 second.
    sleep 1s
 
    output_filename=screenshot_$(date +%Y-%m-%d_%H.%M.%S).png
 
    # Whether to beep or not.
    if [ "${no_beep}" = "-q" ] || [ "${no_beep}" = "-s" ]; then
        magick import -silent -window root "${output_filename}"
    else
        magick import -window root "${output_filename}"
    fi
 
    echo "${output_filename}"
 
done

Take screenshot forever command

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.