How to replace file names with Automator on Mac

Updated : Dec 09, 2021

Even if they can be used as file names on Mac, they may not be possible to upload because there are characters that cannot be used with OneDrive, a cloud service.

So, I used “Automator” on Mac to automate the replacement of file names, so I will show you how to do it.

I think that there are many people who have only heard the name of “Automator” and have never used it, so I will write it for such beginners on this page.

Mr. Otter
Mr. Otter

Automator is a simple program that comes standard with macOS.

Roughly speaking, it’s like an Excel macro.

スポンサーリンク

What made me decide to use Automator

I use Microsoft’s cloud service, OneDrive from multiple environments such as Mac / Windows / Android, but the “|” and “/” that can be used as file names on Mac cannot be uploaded on OneDrive and errors occur.

Mac OneDrive upload error

Initially, I manually replaced “|” and “/” with “_”, which does not cause an error when uploading.

However, I noticed that “|” and “/” are often used in screenshots and PDFs of the site, and I thought that it was not possible to do it manually, so I decided to automate it using Automator, which is a standard function of Mac.

Automator can automate various tasks, but here I tried to create an automatic program for a specific folder called “Folder Action”.

スポンサーリンク

How to create Automator “Folder Action”

The instructions on this page are written on macOS 12 Monterey.

▶ Double-click the “Automator.app” icon in the “Applications” folder of the Finder to launch it.

Mac Finder "Automator.app"

▶ When the file operation dialog box is displayed as shown below, specify an appropriate save location in ① and click the button “New Document” in ②.

As for the save location in ①, you can specify any location you like, but if you save it in iCloud as shown in the figure, it can be read from any Mac and backed up automatically, so it is recommended.

Mac Automator File Operation
Click to enlarge

▶ When “Choose a type for your document” is displayed as shown in the screen below, select “Folder Action” in ①, and then click the “Choose” button in ②.

Mac Automator "Choose a type for your document"
Click ton enlarge

▶ When the screen below appears, assemble the workflow.

Mr. Otter
Mr. Otter

From here, the explanation will continue for a while.

I will explain it carefully with illustrations, so please do your best to follow me.

Mac Automator
Click to enlarge

▶ Drag and drop “Rename Finder Item” on the left side of the screen to the area on the right side.

Mac Automator
Click to enlarge

▶ If you see the screen below, “This action will change the names of the Finder items passed into it.”, this time we will change the file name and replace it, so click the “Don’t Add” button.

Mac Automator

▶ When the action has been added as shown in the screen below, set the each item as follows.

Mac Automator
Click to enlarge

This time, if the file name contains “|”, replace it with “_”.

Therefore, change the action settings as shown in the screen below.

  • ① Action type: Select “Replace Text”
  • ② Find : “|” (do not need to enter ” before and after)
  • ③ Replace: “_” (do not need to enter ” before and after)
Mac Automator
Click to enlarge

▶ Continue to add another same action.

The method is the same as the first one.

Mac Automator
Click to enlarge

The second action, if the file name contains “/”, replace it with “_”.

Therefore, change the action settings as shown in the screen below.

  • ① Action type: Select “Replace Text”
  • ② Find : “/” (do not need to enter ” before and after)
  • ③ Replace: “_” (do not need to enter ” before and after)

① and ③ are the same as the first action, ② is different.

Mac Automator
Click to enlarge

▶ When you have done so far, select the folder to replace the save file name from “Choose folder” in the upper right.。

Here, as an example, select the folder called “monosnap”.

This will cause this action to be performed each time the file is saved in the folder “monosnap”.

【Before the change】

Mac Automator
Click to enlarge

【After the change】

Mac Automator
Click to enlarge

▶ This completes the workflow assembly, so save the file.

Select “File” -> “Save…” from the Automator menu.

Mac Automator

▶ When the dialog box for naming the file is displayed as shown in the screen below, save it with a suitable name.

Mac Automator

▶ After saving, quit Automator.

This is the end of the explanation, “How to create Automator Folder Action”.

Continue to the instructions for running folder actions.

スポンサーリンク

Execution of Automator “Folder Action”

Now let’s see if the “Folder Action”, filename replacement, actually works.

▶ As shown in the screen below, I took a screenshot with the screenshot creation application “Monosnap”.

The file name is attached at the top, but “|” is used as shown in “15 Automator and AppleScripts You Can’t Live Without | TechRadar.jpg”.

Mac monosnap
Click to enlarge

▶ Looking at the saved file, “|” was replaced with “_”.

It’s a success.

Mac Finder
Spa cat
Spa cat

This is the end of this article.

コメント

PHP Code Snippets Powered By : XYZScripts.com
タイトルとURLをコピーしました