Issue with Clipboard Paste in New Tab Automation Script

Hi, all! I think I have encounted a little bizzare problem.
Basically, i want to automate following process:
select a folder in current lister's tab,
open path in a new tab
paste whatever in clipboard (files or folders)
close this new tab
I tried to accomplish following code, which I think have the right logic, but there is one point that I found is not working as expected, that is currentTabPath is always the old tab's path, which prevent from proper pasting.
Any suggestions on how to modify? Thanks!

function OnClick(clickData)
{
    var cmd = clickData.func.command;
    var selectedItem = clickData.func.sourcetab.selected(0);
    DOpus.output('selectedItem'+selectedItem)
    
    var targetPath;

    // Check if the selected item exists
    if (selectedItem != null) {
        // Check if it's a directory or file
        if (selectedItem.is_dir) {
            targetPath = selectedItem.realpath; // Use the directory path if it's a directory
            DOpus.output('targetPath'+targetPath)
            cmd.RunCommand('Go NEWTAB');
            cmd.RunCommand('Go "' + targetPath + '"');
        } else {
            //targetPath = selectedItem.realpath.path; // Use the parent directory if it's a file
        }
    } else {
        // If no selection, default to the current path
        //targetPath = clickData.func.sourcetab.path;
    }
    //DOpus.delay(3000)

    var currentTabPath = clickData.func.sourcetab.path;
    DOpus.output('currentTabPath'+currentTabPath)
    cmd.RunCommand('clipboard paste')
    cmd.RunCommand('Go TABCLOSE PATH="' + targetPath + '"')
  
}

Using

Clipboard PASTE USESEL

instead of a script is not an option?

Thanks a lot. Should have looked into the new version user manual.