I have a batch function that uses IcoFX to convert an image to an icon. In order to use it on multiple images, I must increase a time component within the batch function based on the number of images selected. How do I count the number of files selected and pass that number to a batch function?
Are you using a delay or something, and increasing the delay based on how many images?
There must be a better way to do it than that. Waiting X seconds/milliseconds and assuming something will be finished after that long is rarely a good idea, since it'll go wrong sometimes, and make you wait too long others.
It should be possible to wait for the process to finish if that's what you need, unless it's a tool that doesn't work in the normal way.
Yes, per the IcoFX team. Here's their recommended script:
echo create > myicoscript.fxs
echo {allfilepath} >> myicoscript.fxs
echo -sharpen 2 >> myicoscript.fxs
echo -output {sourcepath} >> myicoscript.fxs
start "" /B "C:\Program Files (x86)\icofx3\icofx3.exe" myicoscript.fxs
set /A time=10 + 1 * {????} ;input file count here
timeout /T %time%
taskkill /F /IM icofx3.exe
To honor the IcoFX spirit of lumberjack coding I suggest that number gets computed by counting the lines in myicoscript.fxs
with the DOS find
command.
I don't think Find will work as I don't see a way for it to identify selected files. That said, love the "lumberjack coding" reference!
Well, yes, find
will not see the selected files in Opus. But the files are listed in myicoscript.fxs
. Okay, they will be all in one line, so counting the lines will not work, but counting e.g. file extensions should actually do the trick. A web search will quickly reveal a couple examples, mostly one-liners.
Using JScript is probably a better idea at this point, as then you can count things and output whatever format of text file is required.
So how do I get this:
@script:jscript
function OnClick(data) {
var tab = data.func.sourcetab;
var count = tab.selstats.selfiles;
DOpus.Output (count);
}
To go into this:
echo create > myicoscript.fxs
echo {allfilepath} >> myicoscript.fxs
echo -sharpen 2 >> myicoscript.fxs
echo -output {sourcepath} >> myicoscript.fxs
start "" /B "C:\Program Files (x86)\icofx3\icofx3.exe" myicoscript.fxs
set /A time=10 + 1 * {????} ;input file count here
timeout /T %time%
taskkill /F /IM icofx3.exe
Still stuck on this. I'm a novice coder at best, so would appreciate continued expert insight.
Something like this, maybe:
function OnClick(data)
{
var tab = data.func.sourcetab;
var count = tab.selstats.selfiles;
var allfilepath = "";
for (var eSel = new Enumerator(tab.selected); !eSel.atEnd(); eSel.moveNext())
{
allfilepath += '"' + eSel.item() + '" ';
}
var cmd = DOpus.Create.Command;
cmd.SetType("msdos");
cmd.AddLine('cd /d "' + tab.path + '"');
cmd.AddLine("echo create > myicoscript.fxs");
cmd.AddLine("echo " + allfilepath + ">> myicoscript.fxs");
cmd.AddLine("echo -sharpen 2 >> myicoscript.fxs");
cmd.AddLine('echo -output "' + tab.path + '" >> myicoscript.fxs');
cmd.AddLine('start "" /B "C:\\Program Files (x86)\\icofx3\\icofx3.exe" myicoscript.fxs');
cmd.AddLine("timeout /T " + (10 + count));
cmd.AddLine("taskkill /F /IM icofx3.exe");
cmd.AddLine("pause");
cmd.Run();
}
Jon,
thanks for this! Oddly, I get the following error:
I double-checked the file path; it's correct. Not sure what's causing this.
Any ideas?
Sorry, the double-backslashes got lost somehow (Jscript needs them for escaping). I've edited the post above, give it another try.
Works like a champ... Thanks Jon!
Not sure when or why, but the script stopped working. It only generates a temp .bat file that includes the following:
@echo off
chcp 1252 > nul
C:
cd "\Users\Chuck\Documents\My Graphics"
echo create > myicoscript.fxs
echo "C:\Users\Chuck\Documents\My Graphics\tag_22.png" >> myicoscript.fxs
echo -sharpen 2 >> myicoscript.fxs
echo -output "C:\Users\Chuck\Documents\My Graphics" >> myicoscript.fxs
start "" /B "C:\Program Files (x86)\icofx3\icofx3.exe" myicoscript.fxs
timeout /T 11
taskkill /F /IM icofx3.exe
pause
It does not actually creates the "myicoscript.fxs" file, open IcoFx or create icons from the selected png files.
Maybe something has messed up your .bat filetype. If you double-click the temporary .bat file (or another .bat) does it work?
Created a very simple hello world batch file named hello.bat
ECHO OFF
ECHO Hello World
PAUSE
Double-clicking the file simply opens the file in Notepad. Strange. Note sure why...
...And fixed. Thanks for the pointer @Jon!