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.
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.
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”
▶ Double-click the “Automator.app” icon in the “Applications” folder of the Finder to launch it.
▶ 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.
▶ 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 ②.
▶ When the screen below appears, assemble the workflow.
From here, the explanation will continue for a while.
I will explain it carefully with illustrations, so please do your best to follow me.
▶ Drag and drop “Rename Finder Item” on the left side of the screen to the area on the right side.
▶ 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.
▶ When the action has been added as shown in the screen below, set the each item as follows.
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)
▶ Continue to add another same action.
The method is the same as the first one.
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.
▶ 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】
【After the change】
▶ This completes the workflow assembly, so save the file.
Select “File” -> “Save…” from the Automator menu.
▶ When the dialog box for naming the file is displayed as shown in the screen below, save it with a suitable name.
▶ 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”.
▶ Looking at the saved file, “|” was replaced with “_”.
It’s a success.
This is the end of this article.
コメント