File name from finder tags?

I tagged a lot of files and now I need to rename these files based on the tags (tagging based on file name would have been a no-brainer …)

Every file contains five to six tags:

  • a tag starting with Quelle_, which should be ignored for naming
  • a tag starting with KB (e.g. KB Alice, which is needed for naming)
  • a tag starting with FN_, which should be ignored for naming
  • a tag with a simple string (e.g. Oslo, which is needed for naming)
  • a tag with the pattern string-string, which should be ignored for naming
  • a tag with a year (e.g. 1991, which is needed for naming)

I would like to use these tags to rename the files like this:

KB Oslo 20000 - Alice - 1991.original file extension

(an individual running number, with five digits and starting at 20000 should be added).

What are my options?

Thanks!

Chris

You say five or six tags, then list six tags, but you don't say which tag may not be there. I'm assuming it's one of the ones that can be ignored for renaming? Can you post some actual examples of the tags, including some of the five variety?

EDIT: In the example you provide, this is confusing:

  • a tag starting with KB (e.g. KB Alice, which is needed for naming)

But then, in the renamed file, you show:

KB Oslo 20000 - Alice - 1991.original file extension

So does this macro have to read the KB Alice tag, then split Alice into a var for later use, because the Oslo free text is what goes after KB, not Alice?

-rob.

Make a counter, starting 20000, that you increment each time through the loop. Then, for each file, get the tags and file extension, then process those plus the counter into the new file name. Rename the file, increment the counter, loop with the next file.

As. well as @griffman's questions, is

  • a tag with a simple string (e.g. Oslo, which is needed for naming)

...distinguishable from the other tags? I.E. does it never start with "Quelle_", "KB", or "FN_" and never contain a "-"?

OK, so here's a first stab while waiting for clarification.

One possible problem is that tags appear to be held as an unordered list -- while KM will probably return them in same order every time it would be better not to rely on that. Instead, we'll iterate through all the tags, testing them to see what they are and processing as appropriate.

You'll need to either edit any tags with a "," in them to remove that character (it's the delimiter in the returned tag list), or if you've always used ", " you could S'n'R it with a unique string then reverse that later.

One big assumption is the only tag with a "-" is the one you want to ignore -- you may have to change that!

The demo uses a local variable for the file counter so it will start at 20000 every time -- the macro can be updated to use a global if the production version requires the value to persist over different runs. And rather than rename files it will pop a text window for each so that you can compare the file's tags and the proposed name.

You didn't say how you'd select files -- this processes the current Finder selection, so select some files and run the macro to see if the results are anything like what you are after.

Rename from Finder Tags.kmmacros (13.6 KB)

Image

I doubt this'll be exactly what you want but all the actions are pretty simple and it'll be easy enough for you to make changes, so see how you get on.