Commands - select (skip), keep extension when renaming file, modifiers

1- selects the first file and every 1 (select the first, skip the second, select the third, skip the fourth...)

Select First
Select Next @nodeselect 

In this case, I don't understand how to use the "skip" command to skip certain files and make the command skip every 1 and select 1, until it's done with all available files, instead of having to instruct it to select the first file, skip second, select third, skip fourth, etc..

2- if there is 1 file selected, it will be renamed to “new name ”(but keeping the file extension) and sent to the folder “C:\Users\lclbl\Past1”. If there is more than 1 file selected, it will be sorted in ascending order, and the files will be renamed with preset “rename123”, and sent to the folder “C:\Users\lclbl\Past2”

Rename PATTERN=* TO=newname Copy MOVE TO ““C:\Users\lclbl\Past1” @ifset:SELECTED=1 Set SORTBY=name SORTREVERSE=off Rename PRESET=rename123 C:\Users\lclbl\Past2” @ifset:else 

I generated this command, but there is something wrong, I tried variations but without success. Also, unable to specify how to use rename keeping file extension in first step "Rename PATTERN= TO=newname

This statement is still true, especially if you invent your own syntax:

Just because there is no error message doesn't mean your syntax is right.

https://resource.dopus.com/t/command-to-use-saved-filter/44498/2

1 Like

I'm trying to learn with examples from the manual and the forum, I don't have any experience with commands. But thank you for your earlier help and patience.

Excellent idea.

However, I would advise against randomly collecting stuff that looks good in a shaker and then rolling the dice as an implementation plan.


Ad 1: Can be done with SelectEx.

Ad 2: Can be done with Rename in two separate buttons. If you insist on using only one button, you need a script to make the case selection.

1 Like

You could get away without a script by selectively showing/hiding the two buttons, like so:

@hidenosel:numfiles=1
Rename PATTERN=* TO=newname IGNOREEXT
Copy MOVE TO="C:\Users\lclbl\Past1"
@hidenosel:minfiles=2
Set SORTBY=name SORTREVERSE=off
Rename PRESET=rename123
Copy MOVE TO="C:\Users\lclbl\Past2"

Give them the same name and icon and no one will ever find out :wink:

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Command_modifier_reference.htm

1 Like

First, thank you very much for your help.
With SelectEx i managed to complete the first step through the command below

SelectEx NTH 2

In the second step, I was correcting the syntax of the commands and created several User-Defined Commands as you taught me in another post. I had to do it this way to stay organized and because using multiple commands without User-Defined made the button not work.

It's been working well, now I'm studying how to create a condition for certain commands to be activated, I've already reviewed a good part of the manual, but I can't find it.

I tried the @hidenosel modifier as suggested but it hasn't worked. The goal would be to create the condition, for example:

If there is 1 file selected, execute command X
Otherwise, run the Y command

You need a script:

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

    if (tab.selected_files.count == 1) {
        cmd.RunCommand('CommandX');
    } else {
        cmd.RunCommand('CommandY');
    }
}
1 Like

Thanks a lot for the script. I used it but there is something strange.

For example, "Command X" is divided into 3 steps (rename, @nodeselect, COPY MOVE TO). "Command X" works fine, but when inserted into the script, it behaves strangely. The file is sent to the target folder, but the name remains the same. So when pressing ctrl + z, the file is returned to the old folder, but with the rename applied (that is, the name that should have been applied).

"Command X" was written as below, and works perfectly except when inserted into the script:

Rename PATTERN=* TO="newname" IGNOREEXT
Copy MOVE TO "C:\Users\lclbl\Past1"

I also tried splitting the "Command X" into two buttons, but now the file is renamed and gives the error "An error ocurred moving "oldnamefile.png": An unknown error ocurred.

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

    if (tab.selected_files.count == 1) {
        cmd.RunCommand('CommandX1');
        cmd.RunCommand('CommandX2');
    } else {
        cmd.RunCommand('CommandY');
    }
}

The old "Command X" was divided down as follows:
CommandX1

Rename PATTERN=* TO="newname" IGNOREEXT`

CommandX2

Copy MOVE TO "C:\Users\lclbl\Past1" 

Stuffing commands into user commands has its place, but this isn't one of them. You need to move in the other direction: put the commands directly into the script.

1 Like

I tried putting the command directly in the script. The rename is applied, but the file is not moved to the destination folder, it shows the error: "An error occurred moving "oldnamefile.png": An unknown error occurred.".

It's interesting that in the error message, it says the name of the old file, not the new one that was applied.

I applied the script as follows

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

    if (tab.selected_files.count == 1) {
        cmd.RunCommand('Rename PATTERN=* TO=newname IGNOREEXT');
        cmd.RunCommand('Copy MOVE TO="C:\Users\lclbl\Past2"');
    } else {
        cmd.RunCommand('Delete');
    }
}

I've also tried including @nodeselect or Select Reselect, but the error persists.

Yes, Rename went to work and told nobody about it. Then Copy was a bit confused. That's life :wink:

It's best to use just one command for both renaming and moving.

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

    if (tab.selected_files.count == 1) {
        cmd.RunCommand('Copy MOVE' +
            ' AS="newname' + tab.selected_files(0).ext + '"' +
            ' TO="C:\\Users\\lclbl\\Past2"'); // in JScript backslashes need to be escaped.
    } else {
        cmd.RunCommand('Delete');
    }
}

Select Reselect

Stay away from Select. That's only useful when you want to select files for the user at the end of your script. Never use it for other commands.

1 Like

Yes, Rename went to work and told nobody about it

It was what I suspected :smile:

It worked fine, but I have a question. Are the commands inside the script standard functions or JavaScript commands?
In the script you provided, ' AS="newname' is used to rename the file, instead of Rename PATTERN=* TO="newname" IGNOREEXT . I didn't understand why the way of writing changed, is this JavaScript?

I tried adapting to use a Preset Rename instead of "'AS="newname'", so I made some adaptations. For example:

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

    if (tab.selected_files.count == 1) {
        cmd.RunCommand('Copy MOVE' +
            ' AS="Preset1' + tab.selected_files(0).ext + '"' +
            ' TO="C:\\Users\\lclbl\\Past2'); //
    } else {
        cmd.RunCommand('Delete'); //
    }
}

The above script didn't work, I probably made a mistake by putting 'Rename PRESET="Rename Player Tie' , as well as I shouldn't have put Rename PATTERN=* TO="newname" IGNOREEXT instead of ' AS="newname', but then the that I should enter?
Can you recommend something so I can study and master DO scripting?
Thank you for your patience and kindness in helping.

As impressive as JScript might look, it's still Opus that runs the show. "All" a script does is generate lines with commands and feed them to Opus via RunCommand().

Both Rename and Copy can rename and move files. Both have their strengths and weaknesses. Here I picked Copy, but Rename would have worked as well.

So, while AS="Preset1' was creative, consulting the docs would have been the better choice:

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Copy.htm

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Rename.htm

Can you recommend something so I can study and master DO scripting?

Lesson 1: Take the script and use Rename instead of Copy.

Tip: Instead of this...

cmd.RunCommand('Copy MOVE' +
    ' AS="newname' + tab.selected_files(0).ext + '"' +
    ' TO="C:\\Users\\lclbl\\Past2"');
}

... use this notation. Lets you dry run and check if you assembled the command line properly.

var cmdLine = 'Copy MOVE' +
    ' AS="newname' + tab.selected_files(0).ext + '"' +
    ' TO="C:\\Users\\lclbl\\Past2"';
DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);
2 Likes

In the manual, I read that there is no "MOVE" argument for the "RENAME" command. Although there is a "TO" argument, it does not serve to direct a file to a folder. I tried a sequence of variations, I changed Copy to Rename, I also tried using both together to specify that I need to move the file to another folder. What I noticed, is that instead of executing the preset, it opens the Rename dialog box. The preset is only executed correctly when I use the command Rename PRESET="Preset1" alone, but when I include other commands with "+"and " ' ", it starts to open the Rename dialog box.

I was checking if the commands I run were correct by looking at the behavior of the files on the side of the screen. So in that case is it still necessary to use the notation you suggested?

var cmdLine = 'Copy MOVE' +
    ' AS="newname' + tab.selected_files(0).ext + '"' +
    ' TO="C:\\Users\\lclbl\\Past2"';
DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);

Run this on a file of your choice:

Rename TO="D:\my totally\new\and\improved path\to\happiness\cutefile.org"

necessary to use the notation you suggested?

No. You can put everything in one line, no problem.

cmd.RunCommand('Copy MOVE AS=newname' + tab.selected_files(0).ext + ' TO="C:\\Users\\lclbl\\Past2"');
1 Like

I can't get the syntax right, where am I going wrong?
In this case I'm trying to apply the preset to several selected files


cmd.RunCommand('Rename' + 'PRESET="Preset1" ' + tab.selected_files.ext + '"' + ' TO="C:\\Users\\lclbl\\Past2"');

cmd.RunCommand('Rename PRESET="Preset1"'  + tab.selected_files.ext + '"' + ' TO="C:\\Users\\lclbl\\Past2"');

Hey friend, I managed to correct the syntax! :grin:

cmd.RunCommand('Rename' +' PRESET="Preset1"' + ' TO="C:\\Users\\lclbl\\Past2"');

Thank you very much for your help and patience, I will mark one of your answers as a solution since it is not possible to mark them all :sweat_smile:

Edit: I found that the applied name is the last folder after the "\"
I'm trying to fix

Run this on a file of your choice:
Rename TO="D:\my totally\new\and\improved path\to\happiness\cutefile.org"

I tried, but "TO" although it moves the file, it influences the name considering what is after the " // " in the destination address. Also, always move to a folder before the last " // "

For example:
When trying to apply a preset rename to multiple files (or just one)

C:\Users\lclbl\Past2\Past3"
Instead of sending to Past3, the command sends to Past2, and gives the file name of Past3 instead of the name configured in the preset

I'm using two "/" inverted as advised

I managed to solve it using the script as a user-button just for rename, and the move part is done from a user-button.
Then I created a button to trigger the two user-buttons, the one that contains the script to rename, and the one that contains a command to select file if it matches the new name made by the script :grin: