What’s up with scripts?

picard
scripting
Tags: #<Tag:0x00007f29fe887a28> #<Tag:0x00007f29fe8878e8>

#1

The interface for scripts has changed a bit in Picard 1.4.2, but there are missing bits. I can add scripts, and they are added to Picard.ini, but I can no longer choose between scripts from the options interface. I also can’t get any scripts to work, but that may have more to do with my scripting skills.:slight_smile:

Could someone shine a light on this? I am using Windows 10.


Author and Composer
#2

That’s a user interface bug that unfortunately did not get fixed in Picard 1.4.2. The list of scripts is hidden, you can make it visible by dragging on the left side of the text area. See the following script:

Regarding you scripting skills: $unset(%script%) does probably not what you want. It would unset a variable with the name stored in the variable %script%. So the following code would unset the variable %myvariable%, not %script%:

$set(script,myvariable)
$unset(%script%)

The proper way to specify variables for $set and $unset is without percentage signs. The following actually unsets %script%:

$set(script,myvariable)
$unset(script)

#3

Does that bug only occur on Windows 10? It worked fine for me on Windows 7 before.

It’s very annoying that you have to use percentage signs in some places, but not in others. It doesn’t help that $unset doesnt work at all here, with or without the tag between percentage signs. And I’ve tried lots of different tags. $set works, $unset doesn’t. Does anyone else have this problem?


#4

No, it occurs on all platforms. It depends on the initial size of the preferences dialog.

It’s rather easy: You use percentage signs to access the value of a variable. When you define variables you just give the name.

Can reproduce. Some tags work, e.g. title and artist, but a lot don’t. Haven’t tried them all, but added a bug report:

https://tickets.metabrainz.org/browse/PICARD-1083


#5

At least Picard scripting has a way to deal with variable references. E.g., you could do something like (may or may not work in Picard):

set(foo,African)
set(bar,European)
if(eq(releasetitle,Your Mother was a Hamster),set(swallow,foo),set(swallow,bar))
set(artist,%swallow%)

This would sometimes set the artist name to “African” and sometimes to “European”. Of course, this is a bad example, since you could just set %artist% straight in the if(), but there are more advanced uses where this can come in handy. :slight_smile: (I’m sure this construct has a proper computer sciency name. It’s fairly common in all the major languages AFAIK, including shell scripting…)


#6

I get tripped up by this, too, but they ARE different things. As @outsidecontext says, without the percentage sign you’re telling Picard what you want that field to say. With percentage signs, you’re asking Picard to look at the actual value of the variable. So $set(mytag,artist) would set mytag to a value of “artist”, whereas $set(mytag,%artist%) would set mytag to whatever value is in the artist field.


#7

Thanks for the explanations, but could someone who fully understands Picard scripting please add that information to the scripting documentation? Because in its current state that page is only useful if you already know how everything works and onlky need some reference.


#8

I have to correct myself here: This already worked in Picard 1.4.2 and works in the latest version as well. What I actually suspect could be the source of confusion is that $unset does not what some here might have thought it does.

When you see the metadata for a track loaded on the right with some files attached you actually have two sets of metadata: The original one in the file and newly loaded data for the track.

Now the general logic is that data present on the track will overwrite data in the file [1]. But data not present in the track will not change the file, which means the original data will be kept. If you run $unset(script), the tag script will be removed from the loaded metadata, but if that tag is also in the file this will be kept. For data you had previously tagged with Picard both the script tag in the file and in the loaded metadata will be the same, so running $unset on it will effectively not change anything.

In the upcoming Picard 2.1 there will be a new function $delete, and this will mark the tag explicitly as deleted. That means using $delete(script) will show the script tag as removed in the metadata view, and upon saving it will be gone. [2]


[1] This is true unless you have “Clear existing tags” selected, in which case existing data obviously gets removed
[2] Edit: I have also the hope that with an explicit delete function people will be less inclined to activate the dreaded “Clear existing tags” function