To batch rename files on Mac, select them in Finder, Control-click the selection, and choose Rename. Finder can replace text, add text, or give files a shared name with a number. For a folder you process repeatedly, the script below adds a prefix to matching files, with a preview before you apply changes.

Use Finder for a selection you want to rename once. Use the script when the same folder and naming rule should run again, including from a Rulr schedule. The script processes files already in a folder; it does not read your Finder selection.

Rename several files in Finder

  1. Open the folder in Finder and select the files you want to rename. Use Command-click for individual files or Shift-click for a range.
  2. Control-click the selection and choose Rename.
  3. Choose the operation that fits your task:
    • Replace Text: replace a shared part of the filenames.
    • Add Text: add text before or after each existing name.
    • Format: use a shared name with an index, counter, or date.
  4. Check the example in the dialog, then click Rename.

For example, Add Text can turn invoice.pdf into project-invoice.pdf. Format is useful when you want numbered names instead of keeping the existing names. Apple’s Rename files, folders, and disks on Mac documents these Finder options.

Try the operation on copies first. Changing a filename can break a link or a workflow that expects the original path.

Preview a repeatable folder rename

The downloadable example keeps each original filename and adds a prefix, such as project-. It is deliberately limited to a fixed folder and extension so you can review exactly what a repeated run will affect.

Download the batch prefix script, read its contents, and save it as batch-prefix-files.sh in a folder you control. The commands below assume you saved it in Documents/Rulr Scripts.

Create a folder called Rename Demo inside Documents and put copies of a few PDFs there. In Terminal, run:

/bin/bash "$HOME/Documents/Rulr Scripts/batch-prefix-files.sh" preview "$HOME/Documents/Rename Demo" pdf project-

The four arguments after the script path are:

ArgumentExampleMeaning
ModepreviewPrint the proposed names without changing files. Use apply to rename.
Folder"$HOME/Documents/Rename Demo"An existing absolute folder path. Quote paths containing spaces.
ExtensionpdfMatch this extension without a leading dot; matching is case sensitive.
Prefixproject-Letters, digits, hyphens, or underscores; the prefix must not be empty.

For two matching files, the preview shows mappings equivalent to:

invoice.pdf → project-invoice.pdf
report.pdf → project-report.pdf

The actual output includes full paths and uses shell escaping for spaces and non-ASCII characters. This changes how the log looks, not the filename stored on disk.

Preview does not rename files or create a lock. Before applying, check the complete list and keep a backup of any originals you need.

Apply the prefix and run it again

Change only preview to apply after checking the result:

/bin/bash "$HOME/Documents/Rulr Scripts/batch-prefix-files.sh" apply "$HOME/Documents/Rename Demo" pdf project-

The script checks every planned destination before the first rename. If a destination already exists, including a directory or symbolic link, it stops without starting the batch. It also uses non-overwriting moves and checks each result.

Running the same command again skips filenames that already begin with project-. Newly added matching files receive the prefix on the next run. A file that already had that prefix before your first run is also skipped; the script does not distinguish how it got its name.

The script:

  • Processes ordinary files in the chosen folder’s first level only.
  • Leaves subfolders, hidden files, and symbolic links alone.
  • Matches .pdf when you pass pdf; .PDF is a different extension.
  • Preserves the original name and file contents; it does not generate sequential numbers or replace text.
  • Creates .rulr-prefix-rename.lock during an apply run to prevent another instance of this script from applying in the same folder at the same time.

Keep the folder unchanged while a batch runs. The lock does not coordinate Finder or other tools. The batch is not a transaction: an interruption, permission change, or file appearing during execution can leave some files renamed. Earlier RENAMED lines describe completed moves when available. Check the folder before retrying; there is no automatic rollback. If a forced termination leaves a lock behind, confirm no run is active before removing the empty lock directory.

Run the folder task with Rulr

To start from a configured workflow, open Batch Prefix Files. The Rule includes the script, starts disabled, and defaults to preview. Set its folder path and review the schedule before enabling it. That detail page also provides the standalone script download.

On Repeat

  1. The timer repeats every 30 minutes between 00:00 and 24:00.

Prefix Matching Files

  1. Run Shell Script using folder="" mode="preview" extensio... with , timeout 30 seconds, and stop this flow if unsuccessful

Rulr’s Run Shell Script Action requires Pro. It can run this fixed folder task from a Trigger, including a schedule. Rulr requires macOS 26 or later.

Start with the same disposable files you used in Terminal:

  1. Add a new Rule and give it a recognizable name, such as Preview PDF prefix.
  2. In When, add Timed Repeat and choose an interval and time range appropriate for your task. A one-minute interval is enough for a short test; disable the Rule after observing the result.
  3. In Do, add Run Shell Script. Choose text script and enter a command like this, replacing both paths with your actual absolute paths:
/bin/bash "/absolute/path/to/batch-prefix-files.sh" preview "/absolute/path/to/Rename Demo" pdf project-
  1. Leave the optional Argument input empty. Start with the default 30-second timeout and keep Stop this flow if unsuccessful enabled.
  2. Enable the Rule, enter Inspect Mode, and wait for the timer. Check the Action’s result and the folder. Preview should succeed while filenames stay unchanged.
  3. Disable the Rule before editing it. Change preview to apply, enable it for a test, and check the names on disk. Disable it again when finished.
  4. After testing, choose the folder and interval for your actual task. Use an interval longer than the expected runtime, and keep a backup.

Use /bin/bash explicitly: the Action runs its text through /bin/sh, while this example uses Bash arrays. Calling the saved file with /bin/bash selects the required interpreter without relying on an executable bit, a shebang being honored by a script editor, or a particular working directory. Keep the invocation in text script mode.

If macOS asks for access to the folder, allow only the access your workflow needs. Permission errors should be resolved for the chosen folder before enabling recurring changes. A successful Terminal run does not by itself prove that Rulr has the same folder access.

Rulr’s captured script output is limited to 1,024 bytes, and Execution Logs redact script text. Inspect Mode is useful for checking success, but its output is not a complete rename history or a rollback file for a large batch. For a complete preview, run the preview command in Terminal before applying changes.

Renaming new arrivals instead

This tutorial scans files already in a fixed folder. If your task is to react to each new file, see Rename New Files on Mac. For a folder event that starts a script, see Run a Shell Script When Files Change; that Gallery example is not this batch script.

Explore more tasks in Mac file automation, or return to the Mac automation guide.

Try a recurring rename task

Start with copies of your files and the Batch Prefix Files Rule. Set your folder, review the preview, and apply the prefix only after checking the proposed names. Run Shell Script requires Pro.

Download Rulr for Mac Explore the Rule Gallery