Pre-process imported Images

I use only a few lua scripts available for DT.
One of those community-scripts is autostyle, it applies styles to RAW/images with selected exif-tags. But what I wanna do, is to apply just two styles to imported images.

While autostyle is awesome and not just some template, I still need some help to change it to my needs. Here’s the relevant part without the exif tags conditions:

local darktable = require "darktable"
local du = require "lib/dtutils"
local filelib = require "lib/dtutils.file"

du.check_min_api_version("7.0.0", "autostyle") 

-- return data structure for script_manager

local script_data = {}

script_data.destroy = nil -- function to destory the script
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet, otherwise leave as nil
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again = nil -- only required for libs since the destroy_method only hides them

-- run command and retrieve stdout
local function get_stdout(cmd)
  -- Open the command, for reading
  local fd = assert(io.popen(cmd, 'r'))
  -- slurp the whole file
  local data = assert(fd:read('*a'))

  -- Replace carriage returns and linefeeds with spaces
  data = string.gsub(data, '[\n\r]+', ' ')
  -- Remove spaces at the beginning
  data = string.gsub(data, '^%s+', '')
  -- Remove spaces at the end
  data = string.gsub(data, '%s+$', '')
  return data

-- Apply the style to an image, if it matches the tag condition
local function autostyle_apply_one_image (image)

  local pref ="autostyle", "exif_tag", "string")
  -- We need the tag, the value and the style_name provided from the configuration string
  local  value, style_name = string.match(pref, "(%g+)%s*=>%s*(%g+)")

if (not value) then
	  darktable.print("value to match not found in " .. pref)
	  return 0
  if (not style_name) then
	  darktable.print("style name not found in " .. pref)
	  return 0

    -- First find the style (we have its name)
  local styles = darktable.styles
  local style
  for _, s in ipairs(styles) do
	  if == style_name then
		  style = s
  if (not style) then
	  darktable.print("style not found for autostyle: " .. style_name)
    return 0

 darktable.print_log("Image " .. image.filename .. ": autostyle automatically applied " .. pref)
 return 1

-- Receive the event triggered
local function autostyle_apply_one_image_event(event,image)

local function autostyle_apply(shortcut)
  local images = darktable.gui.action_images
  local images_processed = 0
  local images_submitted = 0
  for _,image in pairs(images) do
    images_submitted = images_submitted + 1
    images_processed = images_processed + autostyle_apply_one_image(image)
  darktable.print("Applied auto style to " .. images_processed .. " out of " .. images_submitted .. " image(s)")

local function destroy()
  darktable.destroy_event("autostyle", "shortcut")
  darktable.destroy_event("autostyle", "post-import-image")

-- Registering events
darktable.register_event("autostyle", "shortcut", autostyle_apply,
       "Apply your chosen style from exiftool tags")

darktable.preferences.register("autostyle", "exif_tag", "string", "Autostyle: EXIF_tag=value=>style", "apply a style automatically if an EXIF_tag matches value. Find the tag with exiftool", "")

darktable.register_event("autostyle", "post-import-image",

script_data.destroy = destroy
return script_data