Failing to duplicate image in LUA

Hi all,
I am running bleeding edge darktable and trying to automate some procedures like mailing an image to my blog.
With this task I got stuck trying to duplicate an image via lua (Background: I want to “freeze” the published version, and with the lack of “lock” or “freeze” in dt, the best solution is to tag the published version accordingly and create a duplicate as a basis for further processing)
This is what I got so far:

              dt.gui.current_view(dt.gui.views.darkroom)
              dt.gui.views.darkroom.display_image( i )
              dt.control.sleep(1000)
              dt.gui.action("lib/duplicate", 0, "", "", 1.0)
              -- dt.gui.current_view(dt.gui.views.lighttable) 

Unfortunately the dt.gui.action() has no effect. Earlier attempts with

local newi = dt.database.duplicate( i )

were fruitless, too, as I found no way to copy the history stack to the new image.

Any idea would be highly appreciated!

Best regards - Markus

You could try

local newimg = dt.database.duplicate(oldimg)
local tmpstyle = dt.styles.create(oldimg)
dt.styles.apply(tmpstyle, newimg)
dt.styles.delete(tmpstyle)

Thanks, Bill. I’ll try this.