From 95077f639b0345f35f8fb810190202b86c55e88b Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Wed, 17 Jan 2018 10:42:44 +0100 Subject: [PATCH] New script to delete unused tags on startup --- official/delete_unused_tags.lua | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 official/delete_unused_tags.lua diff --git a/official/delete_unused_tags.lua b/official/delete_unused_tags.lua new file mode 100644 index 0000000..337f5f6 --- /dev/null +++ b/official/delete_unused_tags.lua @@ -0,0 +1,46 @@ +--[[ + This file is part of darktable, + copyright (c) 2018 Tobias Ellinghaus + + darktable 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. + + darktable 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 darktable. If not, see . +]] +--[[ +DELETE UNUSED TAGS +A simple script that will automatically delete all tags that are not attached to any images + +USAGE +* require this script from your main lua file +* restart darktable + +all tags that are not used will be automatically deleted at every restart +]] + +local dt = require "darktable" + +dt.configuration.check_version(...,{5,0,0}) + +-- deleting while iterating the tags list seems to break the iterator! +local unused_tags = {} + +for _, t in ipairs(dt.tags) do + if #t == 0 then + table.insert(unused_tags, t.name) + end +end + +for _,name in pairs(unused_tags) do + print("deleting tag `" .. name .. "'") + tag = dt.tags.find(name) + tag:delete() +end