Page 1 of 1

usermenu - how to use parameters

Posted: 14 Mar 2008, 22:11
by aussenboarder
hey.
hopefully you have some advice how i can use the following dos-program
in combination with the userdefined menu of salamander.

normally i use the program jhead to rename jpg-files with the command:

Code: Select all

jhead.exe -n%y%m%d_%H%M%S -exonly *.jpg
i like to add a button in salamander that uses a batchfile so i have the
chance to add a pause-command before the batchfile executes.

Code: Select all

@echo off
echo.
echo ATTENTION !!!
echo ====================
echo.
echo All JPG-files are going to be renamed:
echo yymmtt_hhmmss.jpg
echo.
pause
jhead.exe -n%y%m%d_%H%M%S -exonly *.jpg
how can i use the usermenu to realize this?
thx for advice, aussenboarder

Re: usermenu - how to use parameters

Posted: 14 Mar 2008, 23:00
by cincura.net
And you wanna to use current directory name as parameter to batch file? Then use "$(FullPath)" variable.

Posted: 14 Mar 2008, 23:23
by SvA
Did you try to do it yourself? Where did you run into what difficulty?

You gave too little detail of what you really want to achieve, so I take some assumptions.

Assuming you want to process the files present in the folder displayed in the active panel, the easyest way to create a button that does what you want is to create the .cmd file and simply drag it and drop it on the user menu bar.

Salamander defaults to run the program in the folder mentioned above.

You should use a .cmd file, not a .bat file.

You should quote your %-signs by enering two %% for each one your program needs to see. Otherwise the command processor tries to fill in some environment variables and your jhead.exe probably will not do what you expected.

Posted: 14 Mar 2008, 23:34
by Ether
Then create the batch file, save it somewhere (like 'E:\jpgren.cmd'), create a new user menu item, name it, type the program path 'E:\jpgren.cmd' into the Command field, leave the Arguments field empty, leave Initial directory to be $(FullPath), leave all options set, and enjoy.

Well, it's probably a little bit more difficult than that, otherwise you wouldn't ask, right? You have to escape the percent characters ('%') in the batch file in order to pass them to the program (normally, they're interpreted as variables to be expanded). So, the code

Code: Select all

jhead.exe -n%y%m%d_%H%M%S -exonly *.jpg
            ^^^ ^^^^ ^^^
actually generates a command like

Code: Select all

jhead.exe -nmHS -exonly *.jpg
because there are no environment variables 'y', 'd_' nor 'M' and they're expanded to empty strings.

The code should look like

Code: Select all

jhead.exe -n%%y%%m%%d_%%H%%M%%S -exonly *.jpg
in order to work as wanted, rendering the batch file as follows:

Code: Select all

echo. 
echo ATTENTION !!! 
echo ==================== 
echo. 
echo All JPG-files are going to be renamed: 
echo yymmtt_hhmmss.jpg 
echo. 
pause 
jhead.exe -n%%y%%m%%d_%%H%%M%%S -exonly *.jpg
Please, reply whether this is what you asked for.

@SvA] Looks like you were quicker. :twisted: :idea:

Posted: 17 Mar 2008, 22:07
by aussenboarder
perfect! fantastic! it works!

thank you very much for your help - very fast by the way ;-]
this is exactly what i was looking for. as you already found out, the problem
was that the % became interpretated - but i did not know how to mask it.
sorry - i forgot to mention this important fact.

i try one more question..
do you know whether i can send the selection in the current directory into
the batchfile somehow? for example when i want to change only certain jpegs.

cheers & thanks a lot
aussenboarder

Posted: 17 Mar 2008, 23:32
by Ether
Type this in the argument field, or use the menu (accessed by the arrow on the right)->Advanced->List of Selected Names:

Code: Select all

$(ListOfSelectedNames)
I encourage you to try it with some dummy command at first (with Close shell window disabled) to see what the list actually looks like.

Posted: 19 Mar 2008, 00:40
by aussenboarder
@ether

thank you.
this is more a question how to take it over into the jhead command - so i have
to find an answer somewhere else.

can you tell me, what format the information in the variable $(ListOfSelectedNames)
have? is it an array, or csv? this could help to process them in jhead.

regards, aussenboarder

Posted: 19 Mar 2008, 23:45
by th.
$(ListOfSelectedNames) is expanded as a parameter list appended to the command.
Example: file1.jpg and file78.jpg are selected, command is E:\jpgren.cmd.
So Salamander will create a command line like "E:\jpgren.cmd file1.jpg file78.jpg" to be excuted. In the script the parameters can be accessed with %1, %2 and so on.
Since the number of selected files is variable the script has to loop though the parameters like this:

Code: Select all

@echo off
rem Rename files with jhead
:loop
if %1#==# goto end
jhead.exe -n%%y%%m%%d_%%H%%M%%S -exonly %1
shift
goto loop
:end
Please note there is a maximum length for a command line according to this thread:
http://forum.altap.cz/viewtopic.php?t=2372