Skip to content

Commit fb33171

Browse files
author
preklov
authored
Add files via upload
1 parent 224dce1 commit fb33171

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

contrib/OpenInExplorer.lua

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--[[
2+
OpenInExplorer plugin for darktable
3+
4+
copyright (c) 2018 Kevin Ertel
5+
Update 2020: copyright (c) 2020 Volker Lenhardt
6+
7+
darktable is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
darktable is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
19+
]]
20+
21+
--[[About this plugin
22+
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
23+
24+
----REQUIRED SOFTWARE----
25+
Microsoft Windows or Linux with installed Nautilus
26+
27+
----USAGE----
28+
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
29+
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
30+
2) Require this file in your luarc file, as with any other dt plug-in
31+
32+
Select the photo(s) you wish to find in explorer and press "Go to Folder".
33+
A file explorer window will be opened for each selected file at the file's location; the file will be highlighted.
34+
35+
----KNOWN ISSUES----
36+
Under macOS the file manager Finder opens only once and selects the file name of the last in DT selected image.
37+
]]
38+
39+
local dt = require "darktable"
40+
local du = require "lib/dtutils"
41+
local df = require "lib/dtutils.file"
42+
local dsys = require "lib/dtutils.system"
43+
local gettext = dt.gettext
44+
45+
--Check API version
46+
du.check_min_api_version("5.0.0", "OpenInExplorer")
47+
48+
gettext.bindtextdomain("OpenInExplorer",dt.configuration.config_dir.."/lua/locale/")
49+
50+
local function _(msgid)
51+
return gettext.dgettext("OpenInExplorer", msgid)
52+
end
53+
54+
local act_os = dt.configuration.running_os
55+
local PS = act_os == "windows" and "\\" or "/"
56+
57+
--Detect OS and modify accordingly--
58+
local proper_install = true
59+
if act_os ~= "macos" and act_os ~= "windows" and act_os ~= "linux" then
60+
proper_install = false
61+
dt.print_error(_('OpenInExplorer plug-in only supports Windows and Linux at this time'))
62+
return
63+
end
64+
65+
--The commands to open the OSes' file managers
66+
local fmng_cmd = {}
67+
fmng_cmd.linux = [[busctl --user call org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1 ShowItems ass 1 ]]
68+
fmng_cmd.macos = 'open -R -n '
69+
fmng_cmd.windows = 'explorer.exe /select, '
70+
71+
--The working function that opens the file manager with the image file name selected.
72+
local function open_in_fmanager(os, fmcmd)
73+
local images = dt.gui.selection()
74+
local curr_image = ""
75+
if #images == 0 then
76+
dt.print(_('Please select an image'))
77+
elseif #images <= 15 then
78+
for _,image in pairs(images) do
79+
curr_image = df.sanitize_filename(image.path..PS..image.filename)
80+
local run_cmd = fmcmd..curr_image
81+
if os == 'linux' then run_cmd = run_cmd .. [[ ""]] end
82+
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
83+
resp = dsys.external_command(run_cmd)
84+
end
85+
else
86+
dt.print(_('Please select fewer images (max 15)'))
87+
end
88+
end
89+
90+
91+
-- GUI --
92+
if proper_install then
93+
dt.gui.libs.image.register_action(
94+
_("Show in file explorer"),
95+
function() open_in_fmanager(act_os, fmng_cmd[act_os]) end,
96+
_("Opens File Explorer at the selected image's location")
97+
)
98+
end

0 commit comments

Comments
 (0)