Ok, I cobbled together a lua script that calls an external tool. There
were already scripts doing something similar, but they attempt to copy
back the result from the external program back to Darktable, which is
not applicable for my use case.

This also makes the script much shorter and very easy to understand.
It should be easily adaptable for anyone who wants to "export"
individual files to an external command.

In my case, the external command is `ffmpeg -i {FILENAME} -f apng - |
xclip -selection clipboard -target image/png`. Xclip to get data into
the clipboard, and ffmpeg to quickly convert anything to png (which
many applications seem to prefer as a clipboard data type). I could
also have limited the exporter to PNG, but then I'd have to remember
to switch back when I want to export to filesystem.

Cheers
Moritz

On Sat, Apr 18, 2020 at 4:16 PM Moritz <moritz.schallabo...@gmail.com> wrote:
>
> Hello all,
>
> sometimes I just want to quickly share an image via copy/paste. Is
> there any way to export an (individual) image to the clipboard? I kind
> of hoped pressing Ctrl-C would do the job, but no. Currently I'm using
> the system screenshot tool to (roughly) select the image as rendered
> in the Darktable, which is quite a clutch. But it's much quicker than
> exporting to file system and opening the file in an editor that can
> interact with the clipboard.
>
> Seems like something a LUA script would be able to do, but I don't
> know how to write images to clipboard using LUA. I guess I could call
> an external tool, but that's very system-specific and it's non-obvious
> which external tool to use[1].
>
> Thanks
> Moritz
>
> [1] 
> https://superuser.com/questions/301851/how-to-copy-a-picture-to-clipboard-from-command-line-in-linux

____________________________________________________________________________
darktable user mailing list
to unsubscribe send a mail to darktable-user+unsubscr...@lists.darktable.org
-- title of external tool, used for UI actions
local title = "clipboard"

-- the external tool that will be called (once per image)
-- {FILENAME} is replaced by the filename, {MIME} by the selected format's mime type
local external_tool = "ffmpeg -i {FILENAME} -f apng - | xclip -selection clipboard -target image/png"

-- if you have more than one instance of this lua, you need to increment this number so that DT can tell them apart
local number = "1"

local dt = require "darktable"
local df = require "lib/dtutils.file"
local dtsys = require "lib/dtutils.system"

local function exportSingle(storage, image, format, filename, number, total, high_quality, extra_data)
  filename = df.sanitize_filename(filename)

  local command = external_tool
  command = string.gsub(command, "{FILENAME}", filename)
  command = string.gsub(command, "{MIME}", format.mime)

  local retval = dtsys.external_command(command) 

  dt.print_log("return value " .. retval .. " for " .. command)

  if retval ~= 0 then
    dt.print("could not run external command " .. title)
  else 
    dt.print(string.format("exported image %i/%i to " .. title, number, total))
  end
end

dt.register_storage("export_external_" .. number, title, exportSingle, nil, nil, nil, nil)

Reply via email to