Clarification on Adding a Tag Only If It Does Not Already Exist?

Searching reveals many threads about tagging, preserving, adding to the don’t overwrite list, etc. Reading all that stuff has made it a -less- clear to me now, trying various things as I interpret them with the “Preserve Existing Tag” stuff… doesn’t seem to be working how I want it.

What I would like to do is:

When Loading to the Left
If a tag is already populated/present, leave it alone.
If a tag is not present, create/set it with a value of '1' (or whatever)

As an example, if the track has %genre% already populated, whatever it is, keep it.
But if not, add a %genre% tag with a value of 1.

There’s going to be 10 different ways from Sunday to do it I’m sure… I don’t care how. I just want it to happen when track is loaded.

If needing to be done with scripting, I presume it would be done in a Tagger Script that (I believe) there is a option to have the Tagger Script automatically applied to the tracks as loading?

$if(%tag%,,$set(%tag%,1)

That way when I select a group of tracks on the left/right/wherever, %genre% will already be there so I can just change all those selected ones to whatever.

Yes, if it’s there in at least one, I know I can just add the value to the “New Value” column.

But if I happen to select track(s) that do not have %genre% already in the lower pane, I have to use the contextual menu, add new tag, enter a few characters, click on the one I want, … edit value, etc… and then (Save)

I want to make sure there -something- already in that lower pane so I can set them to whatever I need, or leave it… and yes, I realize if I do nothing else, when that track is saved it will be written with a tag set to a stupid value of 1 if it did not already have something there.

I don’t want to overwrite an existing %genre% so I can have a reference to sort, see, whatever, the data that may have originally been there.

1 Like

The maybe surprisingly simple solution is to add the genre tag to the preserved tags list.

The way preserving tags works is that it makes sure not to overwrite existing data in these tags, but it still will add the tag if it does not exist yet.

For other use cases there are different solutions

  • If you want Picard to never write a tag (not overwriting, not creating new) use a script $unset(tagname) and make sure you have not set “Clear existing tags”. This will clear the data Picard has for this tag. And this means Picard will not attempt to write this data.
  • If you want to actually delete the tag from the files, use $delete(tagname). Like unset this clears the tag in Picard, but also marks it for deletion in the files when saving.
1 Like

This is all predicated on me understanding that there is no such thing as an “empty” tag to Picard.

Is the tag that I want there when the track is loaded?

Yes (Any value) - Carry on.
No: - Create it with a placeholder value.

Continue on as you would. If it’s on the preserve list, It’s preserved with that placeholder value.

If it’s not on the preserved tags list then do what Picard does now.

I’m trying to preempt all the Right-Click, Ad New Tag actions that I’ll have to do if a tag that I intend to use is not in the track already.

$if(%tag%,$noop(Do nothing),$set(%tag%,1)

If I do nothing further with it, I understand that it will be written with the placeholder value if I do nothing further.

If I fetch data from the MBDB, follow the the preserve tag rules. That means that if there was data returned with the MBDB query, the placeholder value changes to whatever that is.

If not, the track will be saved with that placeholder value as if it where there the whole time.

There is no such thing as “preserving with a placehder value”. Preserving means keeping the original value and not overwriting it. What you describe is explicitly overwriting the existing value.

If you always want to to write a tag, and set a fallback value if the data is not set from the MB query, use a script as you suggested. I would just suggest using the $if a bit different:

$if($not(%tag%),$set(tag,1))

Of I personally even prefer this variation, which does basically the same:

$set(tag,$if2(%tag%,1))

Also note that in your example you have $set(%tag%,1), which is probably not doing what you thought it would. $set expects as it’s first parameter the name of the tag, so to set a tag named “tag” call $set(tag,1).

If you pass it a variable the value of this variable will be used as the name. So if %tag% is set to “Jabberwocky” and you do $set(%tag%,1) you will get a variable %Jabberwocky% which is set to “1”. It is the same as calling directly $set(Jabberwocky,1).

2 Likes