SelectNext selects a number of items (files and folders) that come after the current selection. It works like Select NEXT, but can select more than one item. I often use it when I want to launch several .url files but need to be gentle with web servers that don't like to get hammered with too many calls at a time.
The command understands two arguments:
NUMITEMS: determines the number of items to select. If omitted, a default of 15 will be used. Given a negative number, the command will work backward, like Select PREV.
NODESELECT: The current selection will be kept. It's the equivalent of pressing Ctrl when selecting items with the mouse.
I use the commands as hotkeys, but they can be put anywhere you want. Here's my setup:
XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>Select Prev 15</label>
	<tip>Select the previous 15 items (Ctrl to keep selection)</tip>
	<hotkeys>
		<key>alt+J</key>
		<key>ctrl+alt+J</key>
	</hotkeys>
	<function type="normal">
		<instruction>// Opus 12:</instruction>
		<instruction />
		<instruction>// @keydown:alt</instruction>
		<instruction>// SelectNext NUMITEMS=-15</instruction>
		<instruction />
		<instruction>// @keydown:ctrlalt</instruction>
		<instruction>// SelectNext NUMITEMS=-15 NODESELECT</instruction>
		<instruction />
		<instruction>// ---------</instruction>
		<instruction />
		<instruction>// Opus 13:</instruction>
		<instruction />
		<instruction>SelectNext NUMITEMS=-15 {=KeyDown("ctrl") ? "NODESELECT" : ""=}</instruction>
	</function>
</button>
XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>Select Next 15</label>
	<tip>Select the next 15 items (Ctrl to keep selection)</tip>
	<hotkeys>
		<key>ctrl+alt+K</key>
		<key>alt+K</key>
	</hotkeys>
	<function type="normal">
		<instruction>// Opus 12:</instruction>
		<instruction />
		<instruction>// @keydown:alt</instruction>
		<instruction>// SelectNext NUMITEMS=15</instruction>
		<instruction />
		<instruction>// @keydown:ctrlalt</instruction>
		<instruction>// SelectNext NUMITEMS=15 NODESELECT</instruction>
		<instruction />
		<instruction>// ---------</instruction>
		<instruction />
		<instruction>// Opus 13:</instruction>
		<instruction />
		<instruction>SelectNext NUMITEMS=15 {=KeyDown("ctrl") ? "NODESELECT" : ""=}</instruction>
	</function>
</button>
To add the keys, copy the XML code and paste it like this

function OnInit(initData) {
    initData.name = 'SelectNext';
    initData.version = '2023-03-02';
    initData.url = 'https://resource.dopus.com/t/selectnext-select-the-next-n-items/43827';
    initData.desc = 'SelectNext';
    initData.default_enable = true;
    initData.min_version = '12.0';
}
function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'SelectNext';
    cmd.method = 'OnSelectNext';
    cmd.desc = 'Select the next n items in the source';
    cmd.label = 'SelectNext';
    cmd.template = 'numitems/n,nodeselect/s';
    cmd.icon = 'script';
    cmd.hide = false;
}
function OnSelectNext(scriptCmdData) {
    var cmd = scriptCmdData.func.command;
    var tab = scriptCmdData.func.sourcetab;
    var args = scriptCmdData.func.args;
    cmd.deselect = false;
    if (tab.all.count == 0) return;
    var k = args.numitems;
    if (typeof k != 'number' || k == 0) k = 15; // argument is missing, not a number, or zero? use default!
    var i = 0;
    cmd.ClearFiles();
    if (k > 0) {
        if (tab.selected.count > 0) {
            var last = tab.selected(tab.selected.count - 1);
            i = tab.all.count - 1;
            while (last.name != tab.all(i).name) i--;
            i++;
        }
        if (i == tab.all.count) i = 0;
        while (i < tab.all.count && k > 0) {
            cmd.AddFile(tab.all(i));
            i++;
            k--;
        }
    } else {
        if (tab.selected.count > 0) {
            var first = tab.selected(0);
            while (first.name != tab.all(i).name) i++;
            i--;
        }
        if (i < 0) i = tab.all.count - 1;
        while (i >= 0 && k < 0) {
            cmd.AddFile(tab.all(i));
            i--;
            k++;
        }
    }
    if (!args.nodeselect) cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select FROMSCRIPT SETFOCUS');
    cmd.RunCommand('Select SHOWFOCUS');
}
Save CommandSelectNext.js.txt to
%appdata%\GPSoftware\Directory Opus\Script AddIns
and add the new command to a button, hotkey, context menu, etc. like any built-in command.


