Intro to assigning tag fields with scripting on Mac

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%

Artist: Beatles
Title: Yellow Submarine (1969, Ringo Starr, vocal)


  1. 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.
  2. 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.
  3. 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.

The headline claims something different from the actual example.
The example assigns "Beatles" to ARTIST and "Yellow Submarine" to TITLE.

There are many ways to skin a cat - but I think that the action of the type "Format tag field" is a little easier as you can select the target field from a list of fields.
See also the documentation:

You are right: use the Actions if you want to keep the script definition.
Some actions like "Replace" are one-offs in many cases, so it may not be worthwhile to save the configuration. But that depends on the use-case.

Thanks for catching the typo.

You're exactly right there are easier ways to assign simple fields. My issue was I had trouble understanding the examples in the forums since most were fairly complex and as a new user I didn't quite "get it" until I puzzled over various posts for an hour. For me the lights went on once I realized the simplest case was simply a static string vs. some regex I had to parse through.

After I went through (literally) these 4 examples manually I felt like the fog lifted.

Thought I'd post this to hopefully help another new user one day to stick with it and realize how powerful mp3tag is and what a great, feature rich piece of software it is.

A post was split to a new topic: How do I import actions on a Mac