Leading and trailing spaces removal

George Akimov's Avatar

George Akimov

31 Oct, 2017 01:20 AM

1. If you experienced a crash or other abnormal behavior, please attach the log file 'beaTunes-logs-2017-10-30-181426.zip' by dragging it from your desktop onto the 'Attach File' button below.

2. Please enter your message to us here.

It would be nice to add inspection check for leading and trailing spaces and a way to remove them from any tag, similar to https://dougscripts.com/itunes/scripts/ss.php?sp=removeleadingtrailingspaces

* beaTunes: 5.0.5
* JVM: OpenJDK 64-Bit Server VM
* Version: 25.152-b6
* Vendor: JetBrains s.r.o
* OS: Mac OS X 10.12.6, x86_64
* Library: iTunes
* Memory: 92m - 2048m
* Registered as: George Akimov

  1. 1 Posted by George Akimov on 16 Jan, 2018 10:59 AM

    George Akimov's Avatar

    No comments? No reaction? No takers?

  2. Support Staff 2 Posted by hendrik on 16 Jan, 2018 05:52 PM

    hendrik's Avatar

    Hey George,

    apologies, I've never reacted to this. I noticed and the request makes a lot of sense.
    While coding a full blown inspection to do this takes a little bit more effort, a simple beaTlet is a piece of cake. I did and the result is attached.

    To install, unzip the attached file and place the contained file named RemoveWhitespace.groovy in your plugin directory (see http://help.beatunes.com/kb/plugins/how-to-install-a-plugin).

    Note: This is a simple beaTlet. It always operates on the whole library. You cannot select specific fields. Instead, standard fields (name, album, artist, ...) are used.

    Hope this helps,


    PS: I also checked the file into the source code repository on GitHub

  3. Support Staff 3 Posted by hendrik on 16 Jan, 2018 05:54 PM

    hendrik's Avatar

    I should add: After installation of the beaTlet and a beaTunes restart, there should be a new menu item under Tools.

  4. 4 Posted by George Akimov on 27 Jan, 2018 12:56 AM

    George Akimov's Avatar

    Tested it on a quite large library, worked fine and fast too, thank you. There was no clear indication what tracks and fields have been changed, but the Modification time could be used to sort by and see what comes on top.

    Also thanks for pointing me to the plugin API, I may play with it later and do something in Python, seems clear and easy enough to me.

  5. Support Staff 5 Posted by hendrik on 27 Jan, 2018 12:24 PM

    hendrik's Avatar

    Tested it on a quite large library, worked fine and fast too, thank you.

    Please note that, some changes may still be written after the beaTlet ran through.

    Also thanks for pointing me to the plugin API, I may play with it later and do something in Python, seems clear and easy enough to me.

    Awesome! Let me know, in case you have questions (preferably in a new discussion).

    Have a great weekend!

  6. 6 Posted by muell_bin on 20 May, 2018 08:18 PM

    muell_bin's Avatar

    oh noes :(

    java.util.concurrent.RejectedExecutionExeption: Task java.util.concurrent.FutureTask@174190ab receted from com.tagtraum.tunes.TunesUtilities$1@67c99391 etc ...
    pool size 1, threads 1, qued tasks 1000, completed 67

  7. Support Staff 7 Posted by hendrik on 20 May, 2018 10:46 PM

    hendrik's Avatar

    Just wait a little and let it run again...

  8. 8 Posted by evansthompson on 02 Apr, 2020 10:25 PM

    evansthompson's Avatar

    That's awesome! I definitely have that same need.

    I'd love to do something similar with "smart" quotes, which get added when importing metadata from MusicBrainz in another app, for example. It makes a difference in searching and duplicate detection since the "smart" punctuation marks are not the same as the "plain" one, the title/filename whatever don't match and are therefore not duplicates.

    The same song could live in a directory twice, once with smart and once with plain quotes, and most duplicate detection apps or sync apps wouldn't realize it's the same song. Really annoying!

  9. Support Staff 9 Posted by hendrik on 03 Apr, 2020 08:13 AM

    hendrik's Avatar

    Hey Evans,

    forgive me for asking: what exactly are smart quotes? Curly quotes?

    Regular: "
    Curly: “



  10. 10 Posted by evansthompson on 03 Apr, 2020 04:22 PM

    evansthompson's Avatar

    Apologies, hendrik. Yes, curly quotes. I didn't mean to imply the straight
    quotes aren't as intelligent as the curly ones.

    I think I pulled that term from the distant past when word processor
    vendors were proud of themselves and excited being able to "intelligently"
    know which curly quote to replace for their normal brethren.

    Also in this hypothetical character replacement is backtick ` (accent
    grave) replaced with an apostrophe.

    I actually think these characters, leading, trailing, and extra whitespace
    (two or more consecutive spaces) wound be very much at home in the
    Inspection section. They're every bit as annoying as improper /
    inconsistent capitalization and spelling.

  11. Support Staff 11 Posted by hendrik on 05 Apr, 2020 07:33 AM

    hendrik's Avatar

    Apologies, hendrik.

    Ha! No worries. Just wanted to make sure I understand correctly.

    Of course, one could write a beaTlet for this and I am happy to support you, should you be interested in this endeavor. But in many years of running beaTunes, no one has requested an inspection for curly or fancy quotes before (TextEdit indeed has this mechanism for "smart" quotes). This is not to say that it is in invalid request, I just think you may be better served by simply using Find & Replace with regular expressions ("regex"). To open the Find & Replace panel, use Edit -> Find.

    Now, do you want to remove all quotes or do you want to normalize them to all plain quotes?

    To remove you could simply use this regular expression, which means that the Regex checkbox needs to be checked (see attached screenshot):

    Search: “(.*)"
    Replace: $1

    This would match textfields in the visible list starting with a curly quote and ending with a regular quote.

    You can easily modify this to normalize, simply by replaying all fancy quotes (or any other character):

    Replace: '"'

    For this you don't need the Regex checkbox to be on.

    If you want to apply this to your library, first select your Music list and then open the Find & Replace panel. You may also filter for curly quotes before you find and replace, to trim down the list of candidates.

    Hope this helps,


  12. 12 Posted by evansthompson on 08 Apr, 2020 05:37 PM

    evansthompson's Avatar

    OMG. You know, I've never even opened the Find function in beaTunes. I'm usually quite fond of Find and Replace. It always looked like a vestigial OS X/macOS menu that can never be really gotten rid of but isn't always of much use. I just assumed the Filter field was the search/Find capability like iTunes, I suppose.

    Actually, I could probably use this awesome "new" find capability to corral the tracks with the "offending" punctuation and create a playlist from that.

    I do most track editing from Yate. I can script changes plus keep a log of the changes in the event I decided something went awry. Definitely something to play with later!

  13. Support Staff 13 Posted by hendrik on 08 Apr, 2020 06:39 PM

    hendrik's Avatar

    Yep, it's probably one of those under-appreciated features. I wrote a blog post about it back in 2014.

  14. 14 Posted by evansthompson on 11 Apr, 2020 09:35 PM

    evansthompson's Avatar

    I admit the Find/replace feature is really powerful. It wasn't quite what I was expecting, though. I was expecting more of a Filter effect or at least a counter with x of y occurrences. If the playlist is of any substantial size, it's really difficult to see how many instances are affected and to verify the resulting action is appropriate.

    Also, if there's something that significant in the metadata that I'm doing a Find, there's a good chance the metadata isn't as clean as I'd like and there are most likely additional "issues" (not always, but a good chance). (It did give me the idea of creating a Smart Playlist in iTunes/Music for leading/trailing spaces, and that's how I came to the generalization that there's additional metadata that "needed" changing.)

    So...I can't add all the "selected" files to a new playlist, for example, because the matching files aren't selected.

    If even a fraction of that Find capability could be added to the Filter box/feature, that would be amazingly powerful. I don't know of another tool that could do a regex find on an entire existing library. JRiver and Yate are the closest that immediately come to mind, but they would both require creating a new library/database first.

    EDIT: OK, so I didn't give the Filter box enough time to populate. The curly quotes example does work in Filter. Multiple spaces does not. There isn't a significant spike in CPU or a UI change, so I assumed it wasn't found.

    The regex feature and the overlay for replacement are definitely cool.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac