How to run a batch script with @externalonly

I have the following batch script in a button in dopus. For some reason it seems it won't work if I select a video file and click on the button. However if I make a *.bat file with the excat same content (except @externalonly) I am able to run the batch script. Why is this? How can I make the batch script run from inside a button?

<?xml version="1.0"?>
<button backcol="none" display="both" separate="yes" textcol="none">
	<label>Extract part of a video to a new file</label>
	<tip>Extract part of a video to a new file</tip>
	<function type="batch">
		<instruction>@externalonly</instruction>
		<instruction />
		<instruction>@echo off</instruction>
		<instruction />
		<instruction>rem CREDITS: http://stackoverflow.com/questions/8547676/droplet-batch-script-filenames-containing-ampersands</instruction>
		<instruction>rem Explanation: echo off is needed to use rem</instruction>
		<instruction />
		<instruction>set /p startposition=Enter the start position (e.g 00:01:35):</instruction>
		<instruction>set /p endposition=Enter the end position (e.g 00:50:38):</instruction>
		<instruction>rem Explanation: Here we set the timing for where we want to cut the input</instruction>
		<instruction />
		<instruction>setlocal disableDelayedExpansion</instruction>
		<instruction>rem Explanation: Expand variables at parse time rather than at execution time.</instruction>
		<instruction />
		<instruction>rem THE FOLLOWING ENABLES DRAG-AND-DROP FOR THE BATCH SCRIPT</instruction>
		<instruction>rem ---------------------------------------------------------------------------------------</instruction>
		<instruction>:: first assume normal call, get args from %*</instruction>
		<instruction>set args=%*</instruction>
		<instruction>set &quot;dragDrop=&quot;</instruction>
		<instruction>::</instruction>
		<instruction>:: Now check if drag&amp;drop situation by looking for %0 in !cmdcmdline!</instruction>
		<instruction>:: if found then set drag&amp;drop flag and get args from !cmdcmdline!</instruction>
		<instruction>setlocal enableDelayedExpansion</instruction>
		<instruction>set &quot;cmd=!cmdcmdline!&quot;</instruction>
		<instruction>set &quot;cmd2=!cmd:*%~f0=!&quot;</instruction>
		<instruction>if &quot;!cmd2!&quot; neq &quot;!cmd!&quot; (</instruction>
		<instruction>  set dragDrop=1</instruction>
		<instruction>  set &quot;args=!cmd2:~0,-1! &quot;</instruction>
		<instruction>  set &quot;args=!args:* =!&quot;</instruction>
		<instruction>)</instruction>
		<instruction>::</instruction>
		<instruction>:: Process the first argument only</instruction>
		<instruction>for %%F in (!args!) do (</instruction>
		<instruction>if &quot;!!&quot;==&quot;&quot; endlocal &amp; set &quot;dragDrop=%dragDrop%&quot;</instruction>
		<instruction>rem ------------------------------------------------</instruction>
		<instruction>rem - Your file processing starts here.</instruction>
		<instruction>rem - Use %%F wherever you would normally use %1</instruction>
		<instruction>rem</instruction>
		<instruction>rem Change to drive and directory of input file</instruction>
		<instruction>%%~dF</instruction>
		<instruction>cd %%~pF</instruction>
		<instruction>rem ffmpeg: mix to one channel, double the volume</instruction>
		<instruction>rem ffmpeg.exe -i &quot;%%~nxF&quot; -ac 1 -vol 1024 &quot;%%~nF new%%~xF&quot;</instruction>
		<instruction>rem ---------------------------------------------------------------------------------------</instruction>
		<instruction />
		<instruction>rem PUT YOUR FFMPEG INSTRUCTIONS HERE</instruction>
		<instruction>ffmpeg -i &quot;%%~nxF&quot; -c copy -ss %startposition% -to %endposition% &quot;edited-%%~nF%%~xF&quot;</instruction>
		<instruction />
		<instruction>rem ---------------------------------------------------------------------------------------</instruction>
		<instruction>rem</instruction>
		<instruction>rem - Your file processing ends here</instruction>
		<instruction>rem -------------------------------------------------</instruction>
		<instruction>goto :continue</instruction>
		<instruction>)</instruction>
		<instruction>:continue</instruction>
		<instruction>if defined dragDrop (</instruction>
		<instruction>pause</instruction>
		<instruction>rem exit</instruction>
		<instruction>)</instruction>
	</function>
</button>

Please note that I already know how to run an external file but I would like to keep the batch script inside a button.

Things like !cmd2:~0,-1! are .bat file argument syntax. they don't mean anything outside of a .bat file, and inside a .bat file they depend on the arguments on the command line when the .bat file is run.

Within an Opus button, you should use codes like {filepath} and similar if you want to pass selected filepaths into the commands you are running.

I'd also strongly recommend not using .bat for flow control and argument parsing/modifications, as it often leads to pain due to how arcane the old DOS syntax & behavior was, and problems with unicode and so on. Using JScript or VBScript instead will often avoid many headaches.

Try this

@nofilenamequoting
:: @set startposition 00:00:20
:: @set endposition 00:00:30
@set startposition {dlgstring|Enter startposition|00:00:20} 
@set endposition {dlgstring|Enter endposition|00:00:30} 
ffmpeg.exe -i "{filepath$}" -c copy -ss {$startposition} -to {$endposition} "edited-{file$}"
pause