Skip to content

Commit b8d29ca

Browse files
author
preklov
authored
Add files via upload
The new and I hope the finished version for now.
1 parent 90880ff commit b8d29ca

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

contrib/OpenInExplorer.lua

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

0 commit comments

Comments
 (0)