From f8d49ccd017654801b77667963b0fa282c4c9bc1 Mon Sep 17 00:00:00 2001 From: Michael Reiger Date: Sat, 24 May 2025 19:31:23 +0200 Subject: [PATCH 1/4] Modified apply_camera_style script so that the application of a camera style does not mark the image as changed --- official/apply_camera_style.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/official/apply_camera_style.lua b/official/apply_camera_style.lua index b748ef95..2675b672 100644 --- a/official/apply_camera_style.lua +++ b/official/apply_camera_style.lua @@ -60,6 +60,9 @@ local PS = dt.configuration.running_os == "windows" and "\\" or "/" -- command separator local CS = dt.configuration.running_os == "windows" and "&" or ";" +-- tag name for changed images +local changed_tag_name = "darktable|changed" + -- - - - - - - - - - - - - - - - - - - - - - - - -- A P I C H E C K -- - - - - - - - - - - - - - - - - - - - - - - - @@ -313,7 +316,7 @@ local function normalize_maker(maker) return maker end -local function has_style_tag(image, tag_name) +local function has_tag(image, tag_name) local log_level = set_log_level(acs.log_level) @@ -387,11 +390,19 @@ local function apply_style_to_images(images) for i, pattern in ipairs(acs.styles[maker].patterns) do if string.match(model, pattern) or (i == #acs.styles[maker].patterns and string.match(pattern, "generic")) then - local tag_name = "darktable|style|" .. acs.styles[maker].styles[i].name - if not has_style_tag(image, tag_name) then + local style_tag_name = "darktable|style|" .. acs.styles[maker].styles[i].name + if not has_tag(image, style_tag_name) then + local already_changed = has_tag(image, changed_tag_name) image:apply_style(acs.styles[maker].styles[i]) no_match = false log.msg(log.info, "applied style " .. acs.styles[maker].styles[i].name .. " to " .. image.filename) + if not already_changed then + local ct = dt.tags.find(changed_tag_name) + if ct then + log.msg(log.debug, "detaching tag " .. changed_tag_name .. " from image " .. image.filename) + image:detach_tag(ct) + end + end end log.log_level(loglevel) break From 8cd10dce68531895b6a9a21a9f156a8bafe9f2a6 Mon Sep 17 00:00:00 2001 From: Michael Reiger Date: Sun, 1 Jun 2025 12:50:59 +0200 Subject: [PATCH 2/4] Revert "Modified apply_camera_style script so that the application of a camera style does not mark the image as changed" because that attempt did not work. This reverts commit f8d49ccd017654801b77667963b0fa282c4c9bc1. --- official/apply_camera_style.lua | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/official/apply_camera_style.lua b/official/apply_camera_style.lua index 2675b672..b748ef95 100644 --- a/official/apply_camera_style.lua +++ b/official/apply_camera_style.lua @@ -60,9 +60,6 @@ local PS = dt.configuration.running_os == "windows" and "\\" or "/" -- command separator local CS = dt.configuration.running_os == "windows" and "&" or ";" --- tag name for changed images -local changed_tag_name = "darktable|changed" - -- - - - - - - - - - - - - - - - - - - - - - - - -- A P I C H E C K -- - - - - - - - - - - - - - - - - - - - - - - - @@ -316,7 +313,7 @@ local function normalize_maker(maker) return maker end -local function has_tag(image, tag_name) +local function has_style_tag(image, tag_name) local log_level = set_log_level(acs.log_level) @@ -390,19 +387,11 @@ local function apply_style_to_images(images) for i, pattern in ipairs(acs.styles[maker].patterns) do if string.match(model, pattern) or (i == #acs.styles[maker].patterns and string.match(pattern, "generic")) then - local style_tag_name = "darktable|style|" .. acs.styles[maker].styles[i].name - if not has_tag(image, style_tag_name) then - local already_changed = has_tag(image, changed_tag_name) + local tag_name = "darktable|style|" .. acs.styles[maker].styles[i].name + if not has_style_tag(image, tag_name) then image:apply_style(acs.styles[maker].styles[i]) no_match = false log.msg(log.info, "applied style " .. acs.styles[maker].styles[i].name .. " to " .. image.filename) - if not already_changed then - local ct = dt.tags.find(changed_tag_name) - if ct then - log.msg(log.debug, "detaching tag " .. changed_tag_name .. " from image " .. image.filename) - image:detach_tag(ct) - end - end end log.log_level(loglevel) break From e054bfc59d0c8af5734574dc11d6f01d09c839a2 Mon Sep 17 00:00:00 2001 From: Michael Reiger Date: Sun, 1 Jun 2025 13:12:56 +0200 Subject: [PATCH 3/4] Added script to automatically tag manually modified images --- README.md | 1 + contrib/auto_tag_modified.lua | 129 ++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 contrib/auto_tag_modified.lua diff --git a/README.md b/README.md index 8caa5c2e..043e0b50 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Name|Standalone|OS |Purpose ----|:--------:|:---:|------- [AutoGrouper](https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/autogrouper)|Yes|LMW|Group images together by time [autostyle](https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/autostyle)|Yes|LMW|Automatically apply styles on import +[auto_tag_modified](https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/auto_tag_modified)|Yes|LMW|Automatically tag images which have been manually modified in the darkroom change_group_leader|Yes|LMW|Change which image leads group [clear_GPS](https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/clear_gps)|Yes|LMW|Reset GPS information for selected images [CollectHelper](https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/collecthelper)|Yes|LMW|Add buttons to selected images module to manipulate the collection diff --git a/contrib/auto_tag_modified.lua b/contrib/auto_tag_modified.lua new file mode 100644 index 00000000..ea7d94d6 --- /dev/null +++ b/contrib/auto_tag_modified.lua @@ -0,0 +1,129 @@ +--[[ + + auto_tag_modified.lua - automatically take a snapshot when an image is loaded in darkroom + + Copyright (C) 2025 Michael Reiger , modeled after auto_snapshot.lua by Bill Ferguson . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +]] +--[[ + auto_tag_modified - + + automatically tag an image when it has been manually modified in the darkroom, that is if its history has changed at the time it is closed from the darkroom. + (This will not catch applying styles from the light table though.) + + ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT + None + + USAGE + * start the script from script_manager + * open an image in darkroom, and close it after making an operation that changes the history + + BUGS, COMMENTS, SUGGESTIONS + Michael Reiger + + CHANGES +]] + +local dt = require "darktable" +local du = require "lib/dtutils" +local log = require "lib/dtutils.log" + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- C O N S T A N T S +-- - - - - - - - - - - - - - - - - - - - - - - - + +local MODULE = "auto_tag_modified" +local DEFAULT_TAG_NAME = "darktable manually modified" +local DEFAULT_LOG_LEVEL = log.error + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- A P I C H E C K +-- - - - - - - - - - - - - - - - - - - - - - - - + +du.check_min_api_version("7.0.0", MODULE) -- choose the minimum version that contains the features you need + + +-- - - - - - - - - - - - - - - - - - - - - - - - - - +-- I 1 8 N +-- - - - - - - - - - - - - - - - - - - - - - - - - - + +local gettext = dt.gettext.gettext + +local function _(msgid) + return gettext(msgid) +end + + +-- - - - - - - - - - - - - - - - - - - - - - - - - - +-- S C R I P T M A N A G E R I N T E G R A T I O N +-- - - - - - - - - - - - - - - - - - - - - - - - - - + +local script_data = {} + +script_data.destroy = nil -- function to destory the script +script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet +script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again +script_data.show = nil -- only required for libs since the destroy_method only hides them + +script_data.metadata = { + name = _("auto tag modified"), -- name of script + purpose = _("automatically tag an image when it has been manually modified in darkroom"), -- purpose of script + author = "Michael Reiger ", -- your name and optionally e-mail address + help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/contrib/auto_tag_modified/" -- URL to help/documentation +} + + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- L O G L E V E L +-- - - - - - - - - - - - - - - - - - - - - - - - + +log.log_level(DEFAULT_LOG_LEVEL) + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- N A M E S P A C E +-- - - - - - - - - - - - - - - - - - - - - - - - + +local auto_tag_modified = {} + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- P R E F E R E N C E S +-- - - - - - - - - - - - - - - - - - - - - - - - + +dt.preferences.register(MODULE, "auto_modified_tag_name", "string", "auto_tag_modified - " .. _("tag name to use for auto tagging modified images"), + _("tag name to use for auto tagging modified images"), DEFAULT_TAG_NAME) + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- D A R K T A B L E I N T E G R A T I O N +-- - - - - - - - - - - - - - - - - - - - - - - - + +local function destroy() + dt.destroy_event(MODULE, "darkroom-image-history-changed") +end + +script_data.destroy = destroy + +-- - - - - - - - - - - - - - - - - - - - - - - - +-- E V E N T S +-- - - - - - - - - - - - - - - - - - - - - - - - + +dt.register_event(MODULE, "darkroom-image-history-changed", + function(event, image) + local tag_name = dt.preferences.read(MODULE, "auto_modified_tag_name", "string") + local tag = dt.tags.create(tag_name) + dt.tags.attach(tag, image) + end +) + +return script_data From 84fea20ee5c5ac0a86031f66ca406f2b4f69847b Mon Sep 17 00:00:00 2001 From: Michael Reiger Date: Sun, 1 Jun 2025 13:28:44 +0200 Subject: [PATCH 4/4] fixed script desription --- contrib/auto_tag_modified.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/auto_tag_modified.lua b/contrib/auto_tag_modified.lua index ea7d94d6..bceda423 100644 --- a/contrib/auto_tag_modified.lua +++ b/contrib/auto_tag_modified.lua @@ -1,6 +1,6 @@ --[[ - auto_tag_modified.lua - automatically take a snapshot when an image is loaded in darkroom + auto_tag_modified.lua - automatically tag an image when it has been manually modified in darkroom Copyright (C) 2025 Michael Reiger , modeled after auto_snapshot.lua by Bill Ferguson .