Skip to content

Commit fedf222

Browse files
authored
Merge pull request #176 from darktable-org/supertobi-patch-OpenInExplorer
OpenInExplorer
2 parents 3df9040 + 2e5e2e9 commit fedf222

File tree

1 file changed

+63
-31
lines changed

1 file changed

+63
-31
lines changed

contrib/OpenInExplorer.lua

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
--[[OpenInExplorer plugin for darktable
1+
--[[
2+
OpenInExplorer plugin for darktable
23
34
copyright (c) 2018 Kevin Ertel
45
@@ -20,7 +21,7 @@
2021
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
2122
2223
----REQUIRED SOFTWARE----
23-
Microsoft Windows Operating System
24+
Microsoft Windows or Linux with installed Nautilus
2425
2526
----USAGE----
2627
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
@@ -35,47 +36,78 @@ A file explorer window will be opened for each selected file at the file's locat
3536

3637
local dt = require "darktable"
3738
local du = require "lib/dtutils"
39+
local df = require "lib/dtutils.file"
3840
local dsys = require "lib/dtutils.system"
3941

4042
--Check API version
4143
du.check_min_api_version("5.0.0", "OpenInExplorer")
4244

45+
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
46+
4347
--Detect OS and modify accordingly--
4448
local proper_install = false
45-
if dt.configuration.running_os == "windows" then
46-
proper_install = true
49+
if dt.configuration.running_os ~= "macos" then
50+
proper_install = true
4751
else
48-
dt.print_error('OpenInExplorer plug-in only supports Windows OS at this time')
49-
return
52+
dt.print_error('OpenInExplorer plug-in only supports Windows and Linux at this time')
53+
return
54+
end
55+
56+
57+
-- FUNCTIONS --
58+
59+
local function open_in_explorer() --Open in Explorer
60+
local images = dt.gui.selection()
61+
local curr_image = ""
62+
if #images == 0 then
63+
dt.print('please select an image')
64+
elseif #images <= 15 then
65+
for _,image in pairs(images) do
66+
curr_image = image.path..PS..image.filename
67+
local run_cmd = "explorer.exe /select, "..curr_image
68+
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
69+
resp = dsys.external_command(run_cmd)
70+
end
71+
else
72+
dt.print('please select fewer images (max 15)')
73+
end
74+
end
75+
76+
local function open_in_nautilus() --Open in Nautilus
77+
local images = dt.gui.selection()
78+
local curr_image = ""
79+
if #images == 0 then
80+
dt.print('please select an image')
81+
elseif #images <= 15 then
82+
for _,image in pairs(images) do
83+
curr_image = image.path..PS..image.filename
84+
local run_cmd = "nautilus --select " .. df.sanitize_filename(curr_image)
85+
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
86+
resp = dsys.external_command(run_cmd)
87+
end
88+
else
89+
dt.print('please select fewer images (max 15)')
90+
end
5091
end
5192

52-
-- FUNCTION --
53-
local function OpenInExplorer() --Open in Explorer
54-
--Inits--
55-
if not proper_install then
56-
return
57-
end
58-
local images = dt.gui.selection()
59-
local curr_image = ""
60-
if #images == 0 then
61-
dt.print('please select an image')
62-
elseif #images <= 15 then
63-
for _,image in pairs(images) do
64-
curr_image = image.path..'\\'..image.filename
65-
local run_cmd = "explorer.exe /select, "..curr_image
66-
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
67-
resp = dsys.external_command(run_cmd)
68-
end
69-
else
70-
dt.print('please select fewer images (max 15)')
71-
end
93+
local function open_in_filemanager() --Open
94+
--Inits--
95+
if not proper_install then
96+
return
97+
end
98+
99+
if (dt.configuration.running_os == "windows") then
100+
open_in_explorer()
101+
elseif (dt.configuration.running_os == "linux") then
102+
open_in_nautilus()
103+
end
72104
end
73105

74106
-- GUI --
75107
if proper_install then
76-
dt.gui.libs.image.register_action(
77-
"show in file explorer",
78-
function() OpenInExplorer() end,
79-
"Opens File Explorer at the selected image's location"
80-
)
108+
dt.gui.libs.image.register_action(
109+
"show in file explorer",
110+
function() open_in_filemanager() end,
111+
"Opens File Explorer at the selected image's location"
112+
)
81113
end

0 commit comments

Comments
 (0)