How to use tags containing parentheses in a script?

Some tags may use parentheses in their name. (the tag itself, not the content)
E.g. “drums (drumset)”

When trying to use such a tag in a script, Picard throws an error because of these parentheses.
Is there a way to escape these parentheses so you can use such tags in a script?

Have you tried using a backspace? I use it in my file naming script, and it should work in regular scripting as well. Though I am a bit confused, you example drums (drumset) is an example of a tags contents, is it?

Yeah, I tried something like this:
$set(performer:drums,%performer:drums*(drumset*)%)
(I replaced the backslashes with *, because they get removed when posting them)

This is an example of a recording that uses such a tag:

I see that it’s not only parentheses that pose a problem, but spaces also.

Something like:
$set(performer:drums,%performer:guest membranophone%)
is also not accepted in a script by Picard.

Ideas?

The problem here is not only the parantheses but also the spaces in the variable name.

Try something like this:

$set(performer:drums,$get(performer:drums \(drumset\)))
1 Like

Are we in sync, are you clairvoyant, or are you spying on my keystrokes? :wink:

1 Like

I’m sorry, that doesn’t seem to do anything…

(and I don’t understand that there can be a space after ‘drums’ in your line, shouldn’t that be escaped too in some way?)

Works for me, I just got the name wrong. It is “drum set” with a space. You also probably don’t want to have both the “performer:drums” and “performer:drums (drum set)” tags, if so use $unset on the second. This works for me:

$set(performer:drums,$get(performer:drums \(drum set\)))
$unset(performer:drums \(drum set\))

No, because a space is not really a special character in Picard. You can use a space without problems, $set(artist,Michael Jackson) works as expected.

The reason the space caused problems was because it was part of the variable name, and the simple syntax to access a variable is using %somevariable%. But this syntax is only valid as long as there is no space in the variable name, %some variable% is invalid. But for these cases there is the $get function. Using $get(somevariable) is equivalent to the percent sign notation, but now $get(some variable) works as well.

You can do other things with $get as well. E.g. you can access variables that have a special character (with special meaning for Picard’s scripting, like %, $ or parantheses etc.) in their name. E.g. it is totally possible to create a variable with a percent sign with e.g. $set(\%,percent), but you only can access it with $get(\%)

3 Likes

Ah yes, I overlooked that too. Now it works great. Thanks!

If I understand correctly, the $unset function should be read to do something like ‘prevent writing’, and not actually as doing any ‘unsetting’.
What I mean is, if I run the script on existing files, $unset(performer:drums (drum set)) will not do anything, and the “drums (drum set)” tag will remain present.

Are you aware of a script function that can delete specific tags in existing files?
(I am very reluctant to use the atom bomb-like “clear all tags” option)

.
PS
And thanks for explaining $get.
The official Picard documentation says:

$get(name)

  • Returns the variable name (equivalent to %name% ).

But as you explained very well, that’s incorrect. It’s not exactly equivalent.

I think unset is just fine, that’s what it does. After you have $unset a variable it is like you never actually $set it before.

What is missing currently is a function to actually mark a tag as deleted. I have submitted such a function for review, see PICARD-1344. Due to some other issues with deleting tags this function won’t unfortunately work as expected on current Picard 2.0.4, but it will work properly in the coming release (probably 2.1).

2 Likes

That’s great, hopefully it will be there in 2.1.

The word unset is probably a bit dependent on language or interpretation.
(and I am not native a native English speaker)

I personally interpret it as undoing/un-setting/removing something that had been set/entered before.
And that’s one of the things that gave me a hard time understanding scripting when I began.

1 Like

Well, that’s exactly what it is… It’s just getting set by Picard’s internal programming, not your extension of that.

Yeah, I understand that now.
But as a newbee you might think:

$set creates a tag (in your files)
$unset removes a tag (in your files)

That’s what I thought it would do when I started using scripting.

There isn’t an actual ‘remove tag’ scripting command available is there?
(that would be useful)

See @outsidecontext’s post a few posts up:

Great, I just voted for that submission.