Remove Beginning of Filename from IMSLP Downloads


New member, here.

Is it possible to remove the beginning of the filename of pdfs downloaded from IMSLP (Petrucci Music Library)?

The files are named like so: IMSLP513445-PMLP832256-Philipp_-_J_S_Bach_Transcriptions - Prelude

I’d like to remove everything prior to J_S_Bach_Transcriptions - Prelude.

Most of the files vary in length due to the part after (PMLP), but they are contain “-” before the name of the musical composition.

Thank you for your attention.

A solution that works well for you will depend on a few things:

  1. Which, if any, third-party automation tools do you have? Hazel (which I see you’ve tagged the post with) and Keyboard Maestro come to mind, and if you already own one of them, it would be good to use it so you get your money’s worth. Neither are necessary, though.

  2. How would you like the automation to work? For example, it could work by you selecting the files in the Finder and then invoking the automation (through a menu item or keyboard shortcut) to rename the files in place. Or it could rename the files automatically when they’re saved to a specific folder (the Hazel-ish solution).

  3. Most important, how much variation is there in the file names and how do you want to handle it? You mention the PMLP part can be of different length, but other variations can also be important. I downloaded a few files from and got some quite different filename patterns, like


    How would you want these renamed? This strikes me as the most difficult question.

Thank you for taking the time to respond. Yes, upon further inspection, there is more variability than I had thought.

What I want to figure out was a way to get 2 things done:

  1. If the file is called IMSLP4039…PMLP…etc.-Chopin Preludes, Opus 28 to just be called Chopin Preludes, Opus 28.
  2. Then I’d want those files to be moved to specified folder. I was thinking of creating a “Sheet Music” folder and then a folder for different composers in that folder.

I’ve been on a sheet music download spree and my downloads folder (and other folders are a mess). I’m trying to figure out a method to make everything neat and orderly for now and into the future.

I’ll figure out some disciplined approach on my own, I guess.

Once again, I appreciate your time.

All the best.

I didn’t mean to discourage you!

If all the files you have now are named like the example you gave, it’s fairly simple to get them all renamed. And if some future files don’t fit that pattern… well, automations often need adjustment over time.

Here’s something that should work with the files you have. On your Desktop, create two folders, “Original Sheet Music” and “Renamed Sheet Music.” Then open Automator and create this Folder Action:

The Perl script in the Run Shell Script action is

while (<>) {
	@pathParts = split(/\//);
	$oldName = pop(@pathParts);
	$oldDir = join('/', @pathParts);
	if ($oldName =~ m/^IMSLP\d+?-PMLP\d+?-.+?-/) {
		$newName = $oldName;
		$newName =~ s/IMSLP\d+?-PMLP\d+?-.+?-_?(.+)/$1/;
		chdir $oldDir;
		rename $oldName, "../Renamed Sheet Music/$newName";

When you drop files into “Original Sheet Music,” they’ll be renamed and moved over to “Renamed Sheet Music.” Files whose names don’t fit the pattern will remain in “Original Sheet Music.”

No worries.

Thanks for taking the time to come up with that.

Unfortunately it didn’t work.

I’ll find a good solution.

All the best.