Using SetAttr META only on selected files of certain type

I’m hoping to be able to use the following, but only on selected JPEGs, PNGs and TIFFs (meaning I might have files of other types selected, but don’t want them operated on by this, and might also have other JPEGs/PNGs/TIFFs displayed in SOURCE lister, but not selected, and not intended for this operation):

SetAttr FILE "{allfilepath$}" META …

I see here that there’s a PATTERN argument for the COPY command, but I don’t see any such argument or equivalent way of doing what I want with SetAttr. Is it possible? If not, could I request a feature enhancement to the various relevant filename-passing codes ({allfilepath$}, etc.) to introduce a new modifier that lets the user specify a pattern to be matched ONLY among the selected files?

You could de-select everything that isn't a JPEG, PNG or TIFF first, and then run the SetAttr command on what's left:

Select ~(*.(jpg|jpeg|png|tif|tiff)) DESELECT
SetAttr META comment:Test

(I often recommend against changing the selection to change what subsequent commands run on, but if you're deselecting things you want to be left alone, it makes a bit more sense. An alternative would be to have a script which removes the unwanted items from the command object before running the SetAttr command on what's left, but that's probably overkill in this situation, unless you want to leave the untouched files selected afterwards.)

Thanks, though none of the suggestions are quite ideal for my purposes, but if they’re what’s available, I’ll make do.

Out of curiosity, is my suggested feature enhancement feasible and/or potentially to be kept under consideration?

If you give more detail, I might be able to suggest something better.

You can use scripting to do that now. Using {allfilepath} for internal commands wouldn't usually make sense as a solution, even if it could filter by extension. (It's for external commands; internal commands can access the list of selected files in a more efficient way which isn't subject to parsing issues and command-line length limitations.) But if you tell us what the issues with the proposed solution is, we can either suggests alternatives or consider a feature request if one makes sense with the extra information.

I think I started with it in this case because I thought (or at least hoped) there would be some options with it for only operating on the desired, selected files.

Honestly, I was hoping to avoid having to use scripting, if possible. I have done some (mostly minor) non-Opus-related scripting in a few different languages, though usually with major help from others, so I’m certainly not a master of any of them (nor even of Opus custom command construction), and am admittedly reluctant to introduce additional layers of complexity (and the accompanying drain on my time that comes from figuring it all out). My shortcoming, I know. My goal is to achieve what I want as simply as possible, but with as much intelligence and elegance as I can manage.

You don't have to use scripting. You can use the Select command like in my example above.

If there's a problem with doing it that way, let us know the details so we can advise on alternatives.

If this command ends up working the way I’d like it to, here’s an example scenario of its intended usage:

I’ll have a block of associated files of mixed types (different filename extensions), though similar (but not always identical) base names selected. For example:

Image1.png
Image1.docx
Image1.png.json
Image1.png.b64.txt
Image2.jpg
Image2.jpg.xml
Image2.jpg.b64.01 .txt
Image2.jpg.b64.02 .txt
Image2.jpg.b64.03 .txt
Image2.jpg.b64.04 .txt
Image2.jpg.b64.05 .txt
Image2.jpg.b64.06 .txt
Image2.jpg.b64.07 .txt
Image2.jpg.b64.08 .txt
Image2.jpg.b64.09 .txt
Image2.jpg.b64.10.txt
Image2.jpg.b64.11.txt
Image2.jpg.b64.12.txt
Image3.tiff
Image3.html
Image3.maff
Image4.png
Image4.png_original

Ideally, my custom command would operate on the selected PNGs/JPEGs/TIFFs, but would leave ALL files still selected (not only the other files), because there may be additional commands/operations performed on some or all of the files immediately following this one. (Yes, I know about the @nodeselect modifier.)

I think I may have come up with a quasi-solution, still probably far from perfect:

SetAttr FILE "{allfilepath$|noext}.(jpg|jpeg|png|tif|tiff)" META …

…though I suspect — haven’t tested it yet — that it would either end up processing Image1.png and Image3.tiff from the above list multiple times (because Image1 and Image3 are the complete base names of multiple selected files), and/or return lots of errors for all the names it fails to match, etc.

I would not use {allfilepath} like that, as you'll probably run into problems.

Try this instead:

This looks extremely promising. Thanks, Leo! I’m looking forward to giving it a try when I’m home later. As a bonus, it will also increase the likelihood of me trying my own hand at scripting, most likely beginning by reverse-engineering yours.

1 Like