An external editor launcher lua script (for Windows and Linux)

How I wrote in in this post I feel DT is missing a good way to manage external editors.
Some lua scripts are available for Gimp that can be adapted to other programs, but what I wanted was a way to manage multiple programs, even applied in sequence to the same image, not being forced to export the image at every step, creating a new TIF.

So I wrote this lua script, which at the moment is only tested on Windows and for sure need to be refined.

the scripts adds:

  • a new target storage “collection”. Images exported will be reimported to collection for further edit with external programs
    Cattura2
  • a new lighttable module “external editors”, to select a program from a list of up to 9 external editors and run it on one selected image
    Cattura1
  • a set of lua preferences in order to configure name and path for up to 9 external editors
    Cattura3
  • a set of lua shortcuts in order to quick launch the external editors
    Cattura4

More info in the file header.
Hope it can be useful, comments welcome.

Marco

8 Likes

Please make a pull request to the darktable Lua repository. That makes it much easier to review the code and add comments.

1 Like

done

I would like to add another button to the lua module. It becomes like this:
Cattura5
I can’t figure out how to make the two buttons equal in size and taking all the horizontal space, like the other modules, for example:
Cattura6
Any clue ?

Marco

The script now works also without leaving darkroom mode, which is very handy.
Just configure export destination to “collection” before entering darkroom.
From there, CTRL+E will create a new image for external edit.
To edit an image from darkroom, configure and use shortcuts. The image view will be updated when leaving the external program.
The script is now tested in Windows 10 and Ubuntu 19.10.
I created a PR in git

2 Likes

@MarcoNex
nice one, i tested your script and if works well for the UI part, but not so for one line. It is the one exporting / piping output to a MacOs application:

I would need some help to correct the code below:

if dt.configuration.running_os == "macos" then
       program_paths[i] = "open -W -a " .. program_names[i]
else
       program_paths[i] = df.sanitize_filename(dt.preferences.read(MODULE_NAME, "program_path_"..i, "string"))
end

on MacOs, the executables are stored inside a file package, like so:
Gimp.app/Contents/Resouces/MacOs/Gimp
therefore i tried also with
"program_path_".."Gimp.app/Contents/Resouces/MacOs/"..i
…before the grab from the code exporting to Gimp, you’d cited before. But it does not work in both cases. Maybe i am just mistyping something or forgetting sth.

Unfortunately I’m not familiar with MacOS and I didn’t test my script with it, but let’s try.

Plase open a terminal and try to launch Gimp from the command line, like

open -W -a gimp

or

/<puth the correct path here>/Gimp.app/Contents/Resouces/MacOs/gimp

and tell me which one is working

open -W -a gimp

Works great on Macs, I’ve used the other plugin that exports pictures to gimp only. Likewise you, I’m also interested to export to other external editors as well.
After successful execution, this commands logs :

LUA open -W -a '/Applications/Gimp-2.10.app' 'path/to/temporary/items/folder/picture.jpg'

Of course, this command “opens” a target file, so it this call needs to be added when the external editor is triggered and not, when the path to the editor is being registered

For the other path (trying to concatenate strings)
I’ve had no success, even after adding the whole path to the executable

preferences >Lua options >executable for external editor 1

OK, try to use this version

ext_editor.lua.txt (14.7 KB)
(Rename the file to ext_editor.lua)

Then in lua preferences, in “executable for external editor 1” put “gimp” (without quotes) and in “name of external editor 1” put a friendly name for it (“Gimp”, or “GNU Image Processor”, or whatever you like to see in the drop down list).

If it works, do the same with the other programs, you just need to find which command to use from the terminal.

i’ve seen your changes but get still the same error message like before

if not df.check_if_bin_exists(bin) then
    dt.print(friendly_name.._(" not found"))
    return
    end

if i replaced the dt.print line there (line 173) with bin i get:
open -W -a Gimp not found

so, no path is added to the expression. It should look more like:
open -W -a "/Applications/Gimp.app" not found

No, the problem is that checking if the binary exists should be done before prepending “open -W -a”.

Try this version

ext_editor.lua.txt (14.6 KB)

Also try to put “gimp” instead of “Gimp” as executable. Not sure is MacOS is case sensitive.

I tried with
/Applications/GIMP.app
/GIMP.app
/GIMP
GIMP.app
GIMP

in the path field, and tried again both of your attachments
and wrote the names capitalized as they are (case sensitive). On Mac, my Gimp.app sits in the Application folder which is parent to root
/Applications/GIMP.app

and i am still getting
GIMP not found

The lines 126-129 must be responsible for the path string. A dt.print dialog could inform if we found the right path. But, i have also to add and to illustrate more my idea, usually in bash shell script you do not need no path, when launching an app, but only the name of the application package (e.g. “GIMP.app”) to launch the requested process. The "open -W -a " command looks more like a command which does not need paths. I could be wrong.

Anyway, maybe you want to try out some more ideas, if not thanks nevertheless.

You said that the script gimp.lua works for you right ?
If so I will copy from there the way to call executables on Mac.

Affirmative :slight_smile:

I fully copied from gimp.lua, if that works, this version should work too.
ext_editor.lua.txt (14.6 KB)

Please set up preferences like this (respecting letter case)
Cattura13

Plase let me know how it goes.

Good try. But I’ll be honest, it’s still not working.
I can just guess how to change the code as I’ve no idea about Lua :joy:
Ok, let’s try another one…

The gimp.lua script needs a file path to the application bundle, ("/Applications/GIMP.app") so let’s go back to how your original script worked,
replacing the text field of “executable for external editor” with a path chooser popup menu

Name of external editor
Executable for external editor

We should be closer to a solution, because we know how to open files, but the path needs still some tweaking

I don’t see that. This is what gimp.lua does.

local gimp_executable = df.check_if_bin_exists("gimp")

...

   if dt.configuration.running_os == "macos" then
    gimp_executable = "open -W -a " .. gimp_executable
  end

There is no path to application bundle, the program command “gimp” is hardcoded and the filepath is supposed to be returned by the library function df.check_if_bin_exists("gimp")

Now this is what the last version of my script does:

local bin = df.check_if_bin_exists(program_paths[choice])  

...    

if dt.configuration.running_os == "macos" then bin = "open -W -a "..bin end

Which is completely the same if you put “gimp” in executable for editor 1.

I am puzzled, can you help me to clarify ?

I checked /compared both your script and gimp.lua with VisualStudio Code to see if I can do something, with darktable launched from terminal to see what errors might pop up.
I would add more error dialog traps to see what path your script picks up

Yes, apparently gimp.lua needs no path, but it does. The script is an extension of the default export pictures module, so it might get some informations from there.

-Idee•01

As much as I get from this picture, is that the first line defines /switches on an option, which is only a string for the ui, unrelated to a path
The second line defines the path of the executable to launch upon successful export.

The path needs Not to get the full path to the executable itself (e. G. /Applications/GIMP.app/Contents/MacOs/gimp) , but is yet happy to get a path to the application bundle (e. G. /Applications/GIMP.app)

I’m puzzled why your original external editor launcher script didn’t work, a path specification is the best way to launch external files.

Yeah, I see what you mean, but the “select gimp executable” widget seems disconnected from the rest of the code.
Actually, gimp.lua desn’t even work to me on Windows, some scrips just look like abandoned these days…
Try to put whatever other file from the “select gimp executable” widget. Does Gimp start anyway ?

Interesting. The label gimp doesn’t mean anything, it’s only the most obvious choice for retouching pictures (at least for Linux machines), Dt is basically a Linux app.

If I choose another application it launches and opens pictures in another application, as I want.

The Pop up messages /ui labels use the name gimp, but only because that label itself isn’t a variable.