[digiKam-users] Execute a custom script on folder

hleroy hleroy at hleroy.com
Sun May 13 21:57:04 BST 2018


Nice hack Peter. It worked perfectly.

For those interested, the files:

~/.local/share/applications/myRawCleaner.desktop

[Desktop Entry]
Name=Keep CR2 for rated photos
Exec=/usr/bin/konsole -e /bin/bash ~/Scripts/keepRawForRatedPhotos.sh %F
Type=Application
MimeType=image/x-canon-cr2
Terminal=false


~/Scripts/keepRawForRatedPhotos.sh

#!/bin/bash
#
# This script will delete all Raw (CR2) files when the corresponding JPG is
unrated.
# The purpose is to keep only Raw files for photos which are worth it
# (assuming you have gone through the effort of rating them)
#
# It requires a filename as argument. It is meant to be called through a
"context menu"
# (right-click) on a picture
#
# Example .desktop file for KDE (to be placed in
~/.local/share/applications/myRawCleaner.desktop)
#  [Desktop Entry]
#  Name=Keep CR2 for rathed photos
#  Exec=/usr/bin/konsole -e /bin/bash ~/Scripts/keepRawForRatedPhotos.sh %F  
# <-- adjust the script location here
#  Type=Application
#  MimeType=image/x-canon-cr2
#  Terminal=false
#
# **WARNING**
# Make sure to be in the right folder before running this script,
# because it will trash all Raw files with no matching rated JPG
#
# Requires:
#   exiftool
#   trash-cli

# Check that first argument is a file, then extract folder name
if [ -e "$1" ]; then
  ALBUM=$(dirname "$1")
else
  # Otherwise exit
  exit 1
fi

# Check requirements
hash exiftool 2>/dev/null || { echo >&2 "I require exiftool but it's not
installed.  Aborting."; exit 1; }
hash trash-put 2>/dev/null || { echo >&2 "I require trash-put but it's not
installed.  Aborting."; exit 1; }

# List all rated JPG file in the folder
cd "$ALBUM"
RATED_JPG=`exiftool -m -if '$Rating' *.JPG -q -p '$FileName'`

if [[ -z "$RATED_JPG" ]]; then
  echo "No rated photos"
else

  # Create 'Raw' sub-folder if it doesn't exist
  if [ ! -d Raw ]; then
    mkdir Raw
  fi

  # Set line break as field separator and loop throuh all rated JPG files
  IFS=$'\n'
  for JPG in $RATED_JPG
  do
    CR2=${JPG::-4}'.CR2'

    if [ -f "$CR2" ]; then
      echo 'Moving '$CR2
      mv $CR2 Raw
    fi
  done

fi

# Trash remaining Raw files in current folder (needs trash-cli package)
trash-put *.CR2

# Wait for a key press before exiting
read -n 1 -s -r -p "Press any key to continue"






--
Sent from: http://digikam.1695700.n4.nabble.com/digikam-users-f1735189.html



More information about the Digikam-users mailing list