My first try with Lua scripts, Cleansing up with superfluous code and adding support for MacOs.
The original code was written by Kevin Ertel
--[[
OpenInExplorer plugin for darktable
copyright (c) 2018 Kevin Ertel
Modified by: Johans3
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/>.
]]
--[[About this plugin
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
----REQUIRED SOFTWARE----
Linux with installed Nautilus, MacOS or Windows
----USAGE----
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
2) Require this file in your luarc file, as with any other dt plug-in
Select the photo(s) you wish to find in explorer and press "Go to Folder".
A file explorer window will be opened for each selected file at the file's location; the file will be highlighted.
----KNOWN ISSUES----
]]
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local dsys = require "lib/dtutils.system"
--Check API version
du.check_min_api_version("5.0.0", "OpenInExplorer")
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
-- FUNCTIONS --
local function open_in_filemanager()
local images = dt.gui.selection()
local curr_image = ""
local run_cmd = ""
if #images == 0 then
dt.print('please select an image')
elseif #images <= 15 then
for _,image in pairs(images) do
curr_image = image.path..PS..image.filename
if (dt.configuration.running_os == "linux") then
local run_cmd = [[busctl --user call org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1 ShowItems ass 1 ]] .. df.sanitize_filename("file://"..curr_image) .. [[ ""]]
elseif (dt.configuration.running_os == "macos") then
local run_cmd = os.execute("open -R "..curr_image)
elseif (dt.configuration.running_os == "windows") then
local run_cmd = "explorer.exe /select, "..curr_image
end
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
resp = dsys.external_command(run_cmd)
end
else
dt.print('please select less images (max 15)')
end
end
-- GUI --
dt.gui.libs.image.register_action(
"reveal in file manager",
function() open_in_filemanager() end,
"points to the original file on your computer"
)