forked from darktable-org/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_long_tags.lua
More file actions
89 lines (66 loc) · 2.76 KB
/
Copy pathdelete_long_tags.lua
File metadata and controls
89 lines (66 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
This file is part of darktable,
copyright (c) 2014--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 <http://www.gnu.org/licenses/>.
]]
--[[
DELETE LONG TAGS
A simple script that will automatically delete all tags longer than a set length
USAGE
* require this script from your main lua file
* set the the maximum length in darktable's preference
* restart darktable
all tags longer than the given length will be automatically deleted at every restart
]]
local dt = require "darktable"
local du = require "lib/dtutils"
du.check_min_api_version("2.0.0", "delete_long_tags")
local gettext = dt.gettext.gettext
dt.gettext.bindtextdomain("delete_long_tags", dt.configuration.config_dir .."/lua/locale/")
local function _(msgid)
return gettext(msgid)
end
-- return data structure for script_manager
local script_data = {}
script_data.metadata = {
name = "delete_long_tags",
purpose = _("delete all tags longer than a set length"),
author = "Tobias Ellinghaus",
help = "https://docs.darktable.org/lua/stable/lua.scripts.manual/scripts/official/delete_long_tags"
}
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
dt.preferences.register("delete_long_tags", "length", "integer",
"maximum length of tags to keep",
"tags longer than this get deleted on start",
666, 0, 65536)
local function destroy()
-- noting to destroy
end
local max_length = dt.preferences.read("delete_long_tags", "length", "integer")
-- deleting while iterating the tags list seems to break the iterator!
local long_tags = {}
for _,t in ipairs(dt.tags) do
local len = #t.name
if len > max_length then
dt.print_log("deleting tag `"..t.name.."' (length: "..len..")")
table.insert(long_tags, t.name)
end
end
for _,name in pairs(long_tags) do
tag = dt.tags.find(name)
tag:delete()
end
script_data.destroy = destroy
return script_data