RecentToCollection (Create a collection from Recent folders)

RecentToCollection turns the folders from the Recent node in the folder tree into a collection and opens it in the source.

How to set up and use

:one: Save CommandRecentToCollection.js.txt to   

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: Add the new command to a button, hotkey, context menu, or the startup configuration like any built-in command, or run it from the FAYT Command field.

Things you might enjoy reading

Inspired by Recent Locations for new lister

How to use buttons and scripts from this forum

The script's inner workings

function OnInit(initData) {
    initData.name = 'RecentToCollection';
    initData.version = '2024-02-03';
    initData.url = 'https://resource.dopus.com/t/recenttocollection-create-a-collection-from-recent-folders/48571';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'RecentToCollection';
    cmd.method = 'OnRecentToCollection';
    cmd.desc = '';
    cmd.label = '';
    cmd.hide = false;
    cmd.icon = 'script';
}

function OnRecentToCollection(scriptCmdData) {
    var cmd = scriptCmdData.func.command;
    var stt = DOpus.Create().StringTools();
    var fsu = DOpus.FSUtil();

    cmd.deselect = false;

    var recentItem = fsu.GetItem(fsu.Resolve('/dopuslocaldata\\State Data\\recent.osd'));
    if (!fsu.Exists(recentItem)) return;

    var newColl = 'coll://Recent';

    var recentArr = stt.Decode(recentItem.Open().Read(), 'utf8').split('\r\n');
    var re = /.*<pathstring>(.*)<\/pathstring>.*/;

    cmd.ClearFiles();
    for (var i = 0; i < recentArr.length; i++) {
        var tmp = recentArr[i].match(re);
        if (!tmp) continue;
        if (tmp.length != 2) continue;
        var path = tmp[1];
        if (!fsu.Exists(path)) continue;
        if (path == newColl) continue;
        cmd.AddFile(path);
    }

    cmd.RunCommand('Delete FILE="' + newColl + '" QUIET');
    cmd.RunCommand('CreateFolder NAME="' + newColl + '"');
    cmd.SetDest(newColl);
    cmd.RunCommand('Copy COPYTOCOLL=member');
    cmd.RunCommand('Go PATH="' + newColl + '"');
}
7 Likes