Select Between Selected

This script selects all items (files and folders) between the first and the last item of the current selection.

If the selection looks like this

2021-05-07 - 10.55.15

it will look like this after the script has run:

2021-05-07 - 11.01.27

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;

    if (tab.selected.count < 2) return;

    var first = tab.selected(0);
    var last = tab.selected(tab.selected.count - 1);

    cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select FROMSCRIPT');

    do {
        cmd.RunCommand('Select NEXT');
        var item = tab.selected(0);
    } while ( !=;

    cmd.RunCommand('Select FROMSCRIPT');
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>Select Between Selected</label>
	<tip>Select all items between the selection&apos;s first and last item</tip>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (tab.selected.count &lt; 2) return;</instruction>
		<instruction />
		<instruction>    var first = tab.selected(0);</instruction>
		<instruction>    var last = tab.selected(tab.selected.count - 1);</instruction>
		<instruction />
		<instruction>    cmd.ClearFiles();</instruction>
		<instruction>    cmd.AddFile(first);</instruction>
		<instruction>    cmd.RunCommand(&apos;Select NONE&apos;);</instruction>
		<instruction>    cmd.RunCommand(&apos;Select FROMSCRIPT&apos;);</instruction>
		<instruction />
		<instruction>    do {</instruction>
		<instruction>        cmd.RunCommand(&apos;Select NEXT&apos;);</instruction>
		<instruction>        tab.Update();</instruction>
		<instruction>        var item = tab.selected(0);</instruction>
		<instruction>        cmd.AddFile(item);</instruction>
		<instruction>    } while ( !=;</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;Select FROMSCRIPT&apos;);</instruction>
How to

How to use buttons and scripts from this forum