usermenu - how to use parameters

This is a place for users to discuss Altap Salamander. Please feel free to ask, answer questions, and express your opinion. Please do not post problems, bug reports or feature requests here.
aussenboarder
Posts: 4
Joined: 14 Jan 2007, 21:14
Location: Germany

usermenu - how to use parameters

Post 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
cincura.net
Posts: 593
Joined: 09 Dec 2005, 17:30
Location: a step further
Contact:

Re: usermenu - how to use parameters

Post by cincura.net »

And you wanna to use current directory name as parameter to batch file? Then use "$(FullPath)" variable.
Jiri {x2} Cincura
User avatar
SvA
Posts: 483
Joined: 29 Mar 2006, 02:41
Location: DE

Post 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.
User avatar
Ether
Posts: 1471
Joined: 10 May 2007, 16:08
Location: Czech Republic
Contact:

Post 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:
Attachments
the user menu item
the user menu item
jpgren.gif (23.27 KiB) Viewed 9857 times
Ελληνικά rulez.
aussenboarder
Posts: 4
Joined: 14 Jan 2007, 21:14
Location: Germany

Post 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
User avatar
Ether
Posts: 1471
Joined: 10 May 2007, 16:08
Location: Czech Republic
Contact:

Post 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.
Ελληνικά rulez.
aussenboarder
Posts: 4
Joined: 14 Jan 2007, 21:14
Location: Germany

Post 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
User avatar
th.
Posts: 116
Joined: 04 Sep 2006, 23:09
Location: Germany

Post 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
Post Reply