Star Rating (+ toggling) a file `site-wide`

Greetings,

Can`t seem to find how to do this online or in the manual...

I successfully added a Star Rating button (SetAttr META=rating:5) for rating my favorite music tracks. When clicked, it correctly changes the file color to blue, and bolds it as well (via Define Label Filter I previously setup in Prefs / Label Assignments). However, since I have more than one of these matching filenames on my computer, Id like to apply the same blue/boldattributes toall` instances of this file across all my hard drives automatically (even thumb drives). Is this possible with one click?

I also want to be able to toggle said file with/without a star. Not sure how to do this either.

Any ideas would be appreciated.

There's no way to know where or whether other files with the same name exist anywhere on any disk or USB stick, other than searching all of them for the filename.

e.g. You could use Tools > Find Files to do that.

You could set up a script which automates things and does the searching itself, but it would be quite slow since it would have to look through every folder (or at least the locations you know the files might be in).

Tools > Find Files works great... thanks!

PS: When clicking on my Star Rating button, the file gets a rating and turns blue+bold (as scripted). How can I undo and/or reverse this by toggling the same button?

You couldn't really undo a rating change as there's no record of what the previous rating was. (e.g. If the rating was 3 stars and you changed it to 5 stars, there's no way to know it used to be 3 stars and set it back.)

You could have a button which clears the rating if the file already has one (or if the file has a rating and it's the same as the rating the button sets). You would need to use scripting for that, using the scripting API's OtherMeta object to look up the file's current rating before deciding what to do.

Thanks for the reply, Leo.

As a workaround, I created 2 buttons:

button A script is:
SetAttr META=rating:5

... and button B is:
SetAttr META=rating:0

So, clicking button A blue+bolds the file... and button B clears it according to the rule I set up in Favorites and Recent > Label Assignments (which is: Label is Blue and Bold if Rating match is 5 Stars). So far, it works well. Question is: how can I combine these two buttons into 1 toggled button?

Thanks again.

Question is: how can I combine these two buttons

With a little script:

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

    cmd.deselect = false; // Prevent automatic deselection

    for (var eSel = new Enumerator(tab.selected_files); !eSel.atEnd(); eSel.moveNext()) {
        var itemRating = eSel.item().metadata.other.rating;
        if (itemRating == 0 || typeof itemRating == 'undefined') {
            var cmdLine = 'SetAttr "' + eSel.item() + '" META rating:5';
        }
        if (itemRating == 5) {
            var cmdLine = 'SetAttr "' + eSel.item() + '" META rating:0';
        }
        cmd.RunCommand(cmdLine);
    }
}

ToggleRatings.dcf (1.4 KB)

2 Likes

Thanks for this script lxp!

But... I get this error when clicking the button:

Error at line 15, position 9
Invalid procedure call or argument (0x800a0005)

Did you use the script text from above or the .dcf file? Does it happen on all types of files, folders, drives etc.? What version of Opus do you use?

You couldn't post a screenshot of your files, button, error message, could you?

Just got home from work, turned-on my computer and now both the script and the .dcf file/button now work perfectly! Not sure why I got errors previously.

Awesome of you to post this! I will now use your script to learn from.
Thanks lxp... much appreciated!!! :smiley:

1 Like