i've got a simple task i've put as code for a shortcut key :
1- it creates a new folder based on timestamp and move current selected files/folder to that new folder
2- it forces reselection / refocus on newly created folder
3- it is supposed to enter into that newly created folder
step 3 with GO FROMSEL is not working and i cannot understand what is wrong in this last instruction.
nota : here i've put all the patterns code for step 1 with 'rename' but i'm supposed to use a rename preset in my real code. And also i'm using 'details view mode' maybe it has something specific when reselecting and entering folder with "go fromsel".
any idea ?
function OnClick(clickData)
{
var cmd = clickData.func.command;
// 1. move selected items in a new folder
cmd.RunCommand("Rename PATTERN * TO new_{date|MM-dd}-{time|HH}H{time|mm}\\*");
// 2. select the newly created folder and force its focus
cmd.RunCommand("Select TYPE=dirs DATE=created,newest SETFOCUS");
// 3. entering folder
cmd.RunCommand("Go FROMSEL");
}
The Tab object keeps a snapshot of the state the last time it was created or updated. If it kept changing state as things happened, everything would go haywire and you wouldn't be able to do a stable iteration through the list of files selected at the time the button was clicked. You decide when the snapshot is updated, and it remains consistent between updates. It has to or nothing would work properly.
In general, it's also better not to use the selection in this way. Change the selection if you want to change what is selected in the user interface. But don't (unless there's no alternative) think of the selection as a way for one piece of script code to influence what another command or piece of code runs on.
Most internal commands can be given file paths directly as arguments, and you can also define which files the Command objects work on when those arguments are not specified. (The ClearFiles and AddFile methods on the object are the main ones for that.)