Use selected files as parameters to execute Command?
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 26
- Joined: 2009-01-07, 12:31 UTC
Use selected files as parameters to execute Command?
Hi,
My use case is as follows:
I would like to have command (in the toolbar) that takes selected files as input (as %1 and %2) and then execute the defined command.
The command utility is a command-line based pdftk that I use to e.g. stamp PDF-files. Now my question is: how to split (and is it even possible) the below command into executable TC "command" into the "Change single button" window:
pdftk %1 multistamp %2 output stamped.pdf
Where %1 is ment to be the 1st selected file and %2 naturally the second in TC's filebox.
Or do I have to make a simple .BAT -file or .CMD to make this work?
Thx!
//Timo
My use case is as follows:
I would like to have command (in the toolbar) that takes selected files as input (as %1 and %2) and then execute the defined command.
The command utility is a command-line based pdftk that I use to e.g. stamp PDF-files. Now my question is: how to split (and is it even possible) the below command into executable TC "command" into the "Change single button" window:
pdftk %1 multistamp %2 output stamped.pdf
Where %1 is ment to be the 1st selected file and %2 naturally the second in TC's filebox.
Or do I have to make a simple .BAT -file or .CMD to make this work?
Thx!
//Timo
Hi Timo.
- right click an existent button
- chose "Change..."
- press F1 key
- close [Cancel] the button dialog
- read the help:
%P%N = one file
%S, %S1,... %S10 = one or more files
%L, %F = List of all selected files. Use a batch or script to loop over them.
You have to play with correct quoting, %P%N is auto-quoted if space is found, other params you have to quote on yourself.
Or handle quotes in your script, by removing quote if any or not, and add quotes yourself.
I usually use a VBScript to loop over each line of the temp file from the "%L" parameter:
CMD: "D:\rive\path to my\script.vbs"
PARAM: "%L"
There are already maaany scripts to discover in this forum.
Do you need someone to write such script for you?
- right click an existent button
- chose "Change..."
- press F1 key
- close [Cancel] the button dialog
- read the help:
%P%N = one file
%S, %S1,... %S10 = one or more files
%L, %F = List of all selected files. Use a batch or script to loop over them.
You have to play with correct quoting, %P%N is auto-quoted if space is found, other params you have to quote on yourself.
Or handle quotes in your script, by removing quote if any or not, and add quotes yourself.
I usually use a VBScript to loop over each line of the temp file from the "%L" parameter:
CMD: "D:\rive\path to my\script.vbs"
PARAM: "%L"
There are already maaany scripts to discover in this forum.
Do you need someone to write such script for you?
Execute command line tool with two selected files
Just tested:
I think %C1 and %C2 are the right parameters
Copy&Paste button code for testing purpose(copy code, right click TC button bar, paste)
Result (same panel):
or (from both panels)
I think %C1 and %C2 are the right parameters
Copy&Paste button code for testing purpose
Code: Select all
TOTALCMD#BAR#DATA
cmd /k
ECHO pdftk "%C1" multistamp "%C2" output stamped.pdf
C:\windows\system32\cmd.exe
Test pdftk with "%C1"
-1
Result (same panel):
Code: Select all
pdftk "X:\PSPad5\Language\Bulgarian.ini" multistamp "X:\PSPad5\Language\Esperanto.ini" output stamped.pdf
Code: Select all
pdftk "X:\PSPad5\Language\Bulgarian.ini" multistamp "Z:\PDF\pdftk\pdftk.1.txt" output stamped.pdf
-
- Junior Member
- Posts: 26
- Joined: 2009-01-07, 12:31 UTC
Hi:
Thx for supporting me
I think I got forward, but still not success. I even read the help document for that part. Let me try to explain further.
pdftk: that is the name of the executable, runs everywhere from my Command prompt as it's location is added to the Windows 10 variables path.
My current Button command is (in single line):
cmd.exe /c pdftk %S1 multistamp %S2 output stamped.pdf
Parameters: <empty>
Start-path: Defined to the location where %S1 and %S2 files are located.
Stamped.pdf: generated PDF-file after successful execution.
My guess is that those %S1 and %S2 can not be picked to the Command?
What happens: I select from TC the two files (expect them to be the %S1 and %S2) > Click on the button > Some Window just flashes fast (can't see what it says) and no output (stamped.pdf) file is generated.
Thx for supporting me

pdftk: that is the name of the executable, runs everywhere from my Command prompt as it's location is added to the Windows 10 variables path.
My current Button command is (in single line):
cmd.exe /c pdftk %S1 multistamp %S2 output stamped.pdf
Parameters: <empty>
Start-path: Defined to the location where %S1 and %S2 files are located.
Stamped.pdf: generated PDF-file after successful execution.
My guess is that those %S1 and %S2 can not be picked to the Command?
What happens: I select from TC the two files (expect them to be the %S1 and %S2) > Click on the button > Some Window just flashes fast (can't see what it says) and no output (stamped.pdf) file is generated.
Yes, %S1, %S2 is the wrong way for your issue.
Test this button:
CMD: cmd /k
PARAM: ECHO pdftk "%S1" multistamp "%S2" output stamped.pdf
Read the output and understand what %S1 / %S2 does.
- - -
Why not testing my example with %C1, %C2 ?
CMD: cmd /k
PARAM: ECHO pdftk "%C1" multistamp "%C2" output stamped.pdf
Read the output and understand what %C1 / %C2 does.
Next remove ECHO from PARAM, add instead the path(*) to your PDFTK and let it run.
CMD: cmd /k
PARAM: X:\Tools\PDF\pdftk "%C1" multistamp "%C2" output stamped.pdf
If you have space in path to your pdftk.exe, this will be a bit more complicated to quote the whole string.
Copy whole pdftk folder to a path without space and try from there.
(*) That may not be need for you, as your system already knows about pdftk, as you wrote. But may be need for others.
Test this button:
CMD: cmd /k
PARAM: ECHO pdftk "%S1" multistamp "%S2" output stamped.pdf
Read the output and understand what %S1 / %S2 does.
- - -
Why not testing my example with %C1, %C2 ?
CMD: cmd /k
PARAM: ECHO pdftk "%C1" multistamp "%C2" output stamped.pdf
Read the output and understand what %C1 / %C2 does.
Next remove ECHO from PARAM, add instead the path(*) to your PDFTK and let it run.
CMD: cmd /k
PARAM: X:\Tools\PDF\pdftk "%C1" multistamp "%C2" output stamped.pdf
If you have space in path to your pdftk.exe, this will be a bit more complicated to quote the whole string.
Copy whole pdftk folder to a path without space and try from there.
(*) That may not be need for you, as your system already knows about pdftk, as you wrote. But may be need for others.
Last edited by Stefan2 on 2017-05-05, 11:33 UTC, edited 1 time in total.
That do not work.tjsuominen wrote: My current Button command is (in single line):
cmd.exe /c pdftk %S1 multistamp %S2 output stamped.pdf
Parameters: <empty>
...
TCs parameter like %P %N %S %C etc. can normally be use in Parameter field only.
- - -
Again, try with ECHO first:
CMD: cmd /k ECHO pdftk "%C1" multistamp "%C2" output stamped.pdf
PARAM:
RESULT:
pdftk "%C1" multistamp "%C2" output stamped.pdf
- - -
AND use cmd /k instead of /c, just for the testing time.
- - -
And the "Start-path: " can be left empty.
1. As Stefan2 said, you only can use %-parameters in Parameters field, so only cmd.exe should be in Command field. And, %S2 is not a path to second file, it inserts paths to first and second files.tjsuominen wrote:My current Button command is (in single line):
cmd.exe /c pdftk %S1 multistamp %S2 output stamped.pdf
Parameters: <empty>
Start-path: Defined to the location where %S1 and %S2 files are located.
Stamped.pdf: generated PDF-file after successful execution.
2. If you use cmd.exe, it is better to quote full command that is specified after /c to prevent errors caused by quoted program path (dump cmd.exe likes to strip first and last symbol of command line if these symbols are quotes so e.g. command cmd.exe /c "C:\Program Files\App\app.exe" -file "C:\doc.txt" will be broken).
3. It is better to specify full path to output file, e.g. %P if you want it to be created in active panel (it is especially important when you have non-empty Start path).
So I would use such button:
Code: Select all
Command: cmd.exe
Parameters: /c "pdftk "%C1" multistamp "%C2" output "%P\stamped.pdf""
Code: Select all
Command: pdftk
Parameters: "%C1" multistamp "%C2" output "%P\stamped.pdf"
Also keep in mind that you can't control which selected file is %C1 and which one is %C2.
-
- Junior Member
- Posts: 26
- Joined: 2009-01-07, 12:31 UTC