Skip to content

Commit 88c1be0

Browse files
authored
Merge pull request darktable-org#239 from preklov/master
Enabled macOS Finder in OpenInExplorer.lua
2 parents 0bb8b72 + b8d29ca commit 88c1be0

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

contrib/OpenInExplorer.lua

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
OpenInExplorer plugin for darktable
33
44
copyright (c) 2018 Kevin Ertel
5+
Update 2020 and macOS support by Volker Lenhardt
6+
Linux support 2020 by Bill Ferguson
57
68
darktable is free software: you can redistribute it and/or modify
79
it under the terms of the GNU General Public License as published by
@@ -18,18 +20,23 @@ OpenInExplorer plugin for darktable
1820
]]
1921

2022
--[[About this plugin
21-
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
23+
This plugin adds the module "OpenInExplorer" to darktable's lighttable view.
2224
2325
----REQUIRED SOFTWARE----
24-
Microsoft Windows or Linux with installed Nautilus
26+
Apple macOS, Microsoft Windows or Linux
2527
2628
----USAGE----
2729
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
28-
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
30+
1) Copy this file into your "lua/contrib" folder where all other scripts reside.
2931
2) Require this file in your luarc file, as with any other dt plug-in
3032
31-
Select the photo(s) you wish to find in explorer and press "Go to Folder".
32-
A file explorer window will be opened for each selected file at the file's location; the file will be highlighted.
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.
3340
3441
----KNOWN ISSUES----
3542
]]
@@ -38,76 +45,67 @@ local dt = require "darktable"
3845
local du = require "lib/dtutils"
3946
local df = require "lib/dtutils.file"
4047
local dsys = require "lib/dtutils.system"
48+
local gettext = dt.gettext
4149

4250
--Check API version
4351
du.check_min_api_version("5.0.0", "OpenInExplorer")
4452

45-
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
53+
gettext.bindtextdomain("OpenInExplorer",dt.configuration.config_dir.."/lua/locale/")
4654

47-
--Detect OS and modify accordingly--
48-
local proper_install = false
49-
if dt.configuration.running_os ~= "macos" then
50-
proper_install = true
51-
else
52-
dt.print_error('OpenInExplorer plug-in only supports Windows and Linux at this time')
53-
return
55+
local function _(msgid)
56+
return gettext.dgettext("OpenInExplorer", msgid)
5457
end
5558

59+
local act_os = dt.configuration.running_os
60+
local PS = act_os == "windows" and "\\" or "/"
5661

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
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
7468
end
7569

76-
local function open_in_nautilus() --Open in Nautilus
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)
7778
local images = dt.gui.selection()
78-
local curr_image = ""
79+
local curr_image, run_cmd, file_uris = '', '', ''
7980
if #images == 0 then
80-
dt.print('please select an image')
81+
dt.print(_('Please select an image'))
8182
elseif #images <= 15 then
82-
for _,image in pairs(images) do
83+
for _,image in pairs(images) do
8384
curr_image = image.path..PS..image.filename
84-
local run_cmd = [[busctl --user call org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1 ShowItems ass 1 ]] .. df.sanitize_filename("file://"..curr_image) .. [[ ""]]
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)
8596
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
86-
resp = dsys.external_command(run_cmd)
97+
dsys.external_command(run_cmd)
8798
end
8899
else
89-
dt.print('please select fewer images (max 15)')
100+
dt.print(_('Please select fewer images (max 15)'))
90101
end
91102
end
92103

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
104-
end
105-
106104
-- GUI --
107105
if proper_install then
108106
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"
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")
112110
)
113111
end

0 commit comments

Comments
 (0)