I have created a user-defined command (MS-DOS Batch) to convert images to JPG. I need to use an external command for this since the DOpus built-in image converter does not preserve ICC profiles. In any case, I have Imagemagick installed and got my script working. There is just one problem: it processes the selected files all together, but then repeats it again times the number of files selected- which is absolutely not right. Let me explain further. But first, here is the script:
So what I WANT to happen is pretty obvious. I select a couple files, run my command, DOpus passes the filepath of each selected file to the third party app. (Sequentially, though I'm aware I could use @async if I want simultaneous execution, which ultimately I do, but I need to sort this issue out first.) But here is what happens instead, and I noticed this because I put @leavedoswindowopen in there for debugging. Currently what that script does is, if I've selected two files and click my button, a cmd window pops up and I see it process both files. Ok great. But, the DOpus progress bar says 50%, I close the cmd window, and then it does exactly the same thing again. Why?
I noticed this when I tried to batch convert 26 images yesterday and realized it was actually converting the 26 images.... 26 times.
Why is this happening? It does not make sense. I have looked at the documentation thoroughly. DOpus should pass the files one at a time and I cannot figure out how to make it do that.
But I think it will run Image Magic 3 times rather than just once.
The classic solution back in the 2005 era was to run a DOS batch file that first puts the file paths in a text file and then has the executable access the text file.
In the Customize window, I've added a new user-defined command (MS-DOS Batch Function) named "makejpg", which is the code I posted above. Then, in the File Types editor, I went to Images under File Type Groups, went into the Context Menu section, added a new entry called Make JPG, specified as a Standard Function calling just "makejpg". Then, I select my files, and right click and do Make JPG from the context menu.
Thanks for that additional info, I've worked out what's happening now. It's a combination of the user command and special behavior for context menus. For compatibility reasons commands launched from context menus get implicitly told to work on every selected file, so it runs the user command once for each file, which of course then also works on every selected file.
I'm going to put this on the list to see if it can be improved but in the meantime a few ways you could get around it:
Launch the user command from a button or hotkey instead
Add @firstfileonly to the context menu command
Put the command line directly in the context menu rather than via a user command