Shutter count shell script: Help wanted

Hello,

I decided to whip up a quick-and-dirty shell script for reporting the actual shutter count. It works by extracting the required value from a JPEG file using exiftool. The problem is that the only camera manufacturer that actually provides shutter count in the EXIF metadata is Nikon. For others, the only approximation you can get is the Image Count or Image Number values.

This is exactly what the script tries to do. It works with JPEGs from Nikon cameras and Sony’s ILCE-6xxx models, but it doesn’t work with Sony RX100 series and Olympus E-PLx. I wonder whether there is better way to do this? Here is the script in all its crude glory:

#!/usr/bin/env bash

imagenumber=$(exiftool $1 | grep -m 1 "Image Number" | cut -d":" -f2 | tr -d " ")
if [ ! -z "$imagenumber" ]; then
    kdialog --msgbox "Image number: $imagenumber"
fi
imagecount=$(exiftool $1 | grep -m 1 "Image Count" | cut -d":" -f2 | tr -d " ")
if [ ! -z "$imagecount" ]; then
    kdialog --msgbox "Image count: $imagecount"
fi
shuttercount=$(exiftool "$1" | grep "Shutter Count" | cut -d":" -f2 | tr -d " ")
if [ ! -z "$shuttercount" ]; then
    kdialog --msgbox "Shutter count: $shuttercount"
fi

Thanks,
Dmitri

Hi @dmpop,

Your script also works for Fuji X-T1.

Have fun!
Claes in Lund, Sweden

Good to know! thanks for reporting back! :slight_smile:

I would prioritize ShutterCount as it shows the actual number of shutter actuations, and works on DNG, ARW, NEF and PEF.

ExifTool returns 0 if no errors occurred, but when a tag such as ShutterCount is missing that is still not an error.

Your hashbang says you’re using bash, so let’s stick to bash and not spawn processes and long pipes.

I’d use something like:

#!/usr/bin/env bash

c="$(exiftool -s3 -ShutterCount "$1")"
if [[ $c -gt 0 ]]; then
    printf '%s\n' "ShutterCount: $c"
else
    c="$(exiftool -s3 -ImageCount "$1")"
    if [[ $c -gt 0 ]]; then
        printf '%s\n' "ImageCount: $c"
    else
        c="$(exiftool -s3 -ImageNumber "$1")"
        if [[ $c -gt 0 ]]; then
            printf '%s\n' "ImageNumber: $c"
        else
            printf '%s\n' "Unknown"
        fi
    fi
fi
4 Likes
$ exiftool _img4401.dng |grep '^Camera Model\|^Shutter Count'
Camera Model Name               : PENTAX K-1
Shutter Count                   : 4717

I stand corrected. :slight_smile: