From 8cc41b959e38d6c311d719704f855e0b31f00aaa Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Mon, 11 Sep 2023 17:21:02 +0300 Subject: [PATCH] Add mtime script --- .../02_imagetools-dng-cr2.desktop | 7 +++- 4_scripts/imagetools_09_mtime.sh | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 4_scripts/imagetools_09_mtime.sh diff --git a/3_desktop_files_for_kde-plasma-dolphin/02_imagetools-dng-cr2.desktop b/3_desktop_files_for_kde-plasma-dolphin/02_imagetools-dng-cr2.desktop index a55c7d5..16507e7 100644 --- a/3_desktop_files_for_kde-plasma-dolphin/02_imagetools-dng-cr2.desktop +++ b/3_desktop_files_for_kde-plasma-dolphin/02_imagetools-dng-cr2.desktop @@ -3,7 +3,7 @@ Type=Service ServiceTypes=KonqPopupMenu/Plugin Icon=application-x-theme MimeType=image/x-canon-cr2;image/x-adobe-dng; -Actions=convert_dualiso;raw_tags; +Actions=convert_dualiso;raw_tags;correct_mtime; X-KDE-StartupNotify=false X-KDE-Priority=TopLevel X-KDE-Submenu=Image Tools @@ -17,3 +17,8 @@ Exec=/usr/share/kservices5/ServiceMenus/imagetools_02_dualiso.sh %F Name=Rename, Uncrop & Add Baseline Tags Icon=application-x-theme Exec=/usr/share/kservices5/ServiceMenus/imagetools_03_raw_resolution-baseline.sh %F + +[Desktop Action correct_mtime] +Name=Set mtime to DateTimeOriginal +Icon=application-x-theme +Exec=/usr/share/kservices5/ServiceMenus/imagetools_09_mtime.sh %F diff --git a/4_scripts/imagetools_09_mtime.sh b/4_scripts/imagetools_09_mtime.sh new file mode 100644 index 0000000..95ce5f7 --- /dev/null +++ b/4_scripts/imagetools_09_mtime.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +################################################################################################ + +# File system check +# We don't allow writing to SD card. + +#Sed is here to remove any trailing spaces and crap like blank lines +INPUT_FILESYSTEM=$(df -h "${1}" | awk -F ' ' 'FNR> 1 {print $1}' | grep -i -E "/dev/sd?|/dev/hd?|?rewritefs|?tmpfs|/dev/nvme?" | sed '/^\s*$/d' | wc -l) + +if [[ "${INPUT_FILESYSTEM}" -eq 0 ]]; then #if input file (first file printed in bash) filesystem does not start with /dev/sdX + kdialog --error "Image(s) are in a SD Card. Please move them your local or external storage and try again." + exit +fi + +################################################################################################ + + +#We get the directory just from the first filename. Pwd should be easier, but bugged, so... +INPUT_DIR=$(dirname "${1}") +DIR_BASENAME=$(echo "${INPUT_DIR}" | rev | cut -d/ -f 1 | rev) + +while [[ $# -gt 0 ]]; do + +################################################################ + +# Values that change during the while loop (differ from file to file) + + INPUT="${1}" + + MTIME=$(exiftool -d "%s" -DateTimeOriginal -s -S "${INPUT}") + touch --date=@${MTIME} "${INPUT}" + + shift # Move to the next file +done