Some things I had to figure out when trying to write my first script - hopefully helpful to someone.
Important note: to assign tag fields with mp3tag on a Mac using scripting, you use the
Import tag fields Action (as mentioned in numerous places in the Forum).
The Import tag fields Action has two entries: the Source format and the Formatstring.
You use scripting in the Source format and specify the field(s)
to match against the Source format string in Formatstring.
Below are some examples
Assign Beatles to the Artist for selected songs using a static string
Source format: Beatles
Formatstring: %artist%
Assign Beatles to the Artist for selected songs using a silly script
Source format: $reverse(seltaeB)
Formatstring: %artist%
Assign Beatles to the Artist and Yellow Submarine to the Title
Source format: Beatles - Yellow Submarine
Formatstring: %artist% - %title%
Real-world example
Take a filename that includes track number, year, artist, title,
track comment and reformat/assign the appropriate parts to Artist and Title
The filename is: 001 - 1969 Beatles - Yellow Submarine (Ringo Starr, vocal).m4a
Source format: $regexp(%_filename%,'\d+ - (\d{4}) (.+) - (.+) \((.+)\)',$2+++$3 ($1, $4))
Formatstring: %ARTIST%+++%TITLE%
Result
Artist: Beatles
Title: Yellow Submarine (1969, Ringo Starr, vocal)
Notes
- Because
$regexp
REPLACES text in the SOURCE STRING and returns it, this often leads you
write expressions that match the entire string so you can extract just part of the string
with the regex. While this can lead to long and complicated regex patterns, it also assures
that the exact part of the string you want to extract is perfectly matched regardless of
the regex input string value since it inherently makes the match process occur on both value and position. - Using a simple string as a delimiter that will never appear in your source makes assigning
strings to tag fields less error prone. In the example above+++
is as a field delimiter used between artist and title. - I find it much easier to work in Actions vs. Quick Actions when trying to refine a complicated script
since the dialog is dismissed when you apply it and when it doesn't work for me it's faster to get back to
where I was working in Actions to fix the problem and try again.