Renaming multiple tags

I have many tags imported from Evernote. They had their own specific syntax (+ and > at the beginning of each tag). Is it possible to automatically rename tags (remove leading +> characters in each of the tags)?

My solution would be an applescript
but someday I’ll learn that regular expression stuff

Sure there is…
Select the tags group.
Select a tag to modify.
Open Tools > Batch Process.
Then…

You could use Scan Text > String like so…

The asterisk is matched and preserved. The preceding character, here a #, is removed.
The name change is the Insert Placeholder > Document String from the contextual menu.

Or you could use a Scan Name > Regular Expression like this…

Also, see this recent blog post regarding batch processing…

3 Likes

Thank you very much! It works.

Kind regard,
Max

You’re very welcome :slight_smile:

This is very useful! I’ve started using in-text hashtags more, and so I’d like to replace a bunch of spaces in my older tags with underscores.

But I’m new at this, so would appreciate a tiny bit of help. Is what what I want a “scan name > string” process where I replace * * with _ ?

This can’t be done with a String parameter since you want to preserve two separate parts of the name.

You need to use a Regular Expression, though this one is fairly simple.

  • () creates a capture group, i.e., keep this. Each group is numbered from left to right, so we have two here.
  • ^ is an anchor for the beginning of the line. It’s not totally necessary here, but it’s good to know and doesn’t hurt.
  • . matches any character
  • + is a repetition operator denoting at least one of the preceding character, but match more if available.
  • + matches one or more spaces. This can also be more explicitly written as \s+.
  • We create a second capture group matching one or more of any character. $ is the anchor for the end of the line.

In the Change Name action, we string together the captured groups - each with a prefixing backslash - and insert an underscore between them: \1_\2.

Just a little note: Using greedy quantifiers (like ‘.+’ here) is often not a good idea. In this case, they’ll make the RE fail if it contains more than two space separated parts.

@davidsingerman said

I’d like to replace a bunch of spaces in my […] tags with underscores

Suppose you have three tags like
tag1 tag2 tag3
then the desired output would be tag1_tag2_tag3 (I think).
The first part of your RE (“At least one arbitrary character at the beginning of the string”) will match “tag1 tag2” and only then will the space character(s) + be matched. So, \1 will be “tag1 tag2” and \2 will be “tag3”, thus changing the name to tag1 tag2_tag3.
The better way to write the RE here would be (^.+?)\s+(.+)$, but that would gobble up “tag2 tag3” in the second capturing group.

Since @davidsingerman wanted to replace all spaces by underscores, the simple solution (in my mind) would be to use \s+ as a search expression and _ as the replacement.

1 Like

Assumptions on my part… one space between two words.

So here’s the better option @davidsingerman:

Select the tag(s) and use Script menu > Rename > Replace Text.
Enter a space in the first dialog and an underscore in the second, et voila! :slight_smile:

That worked great! Thank you!

You’re welcome :slight_smile: