I promised a discussion of Automator “next week” two weeks ago. Life happens! So why was I interested in Automator anyway?
It was one of those “jump in and get it done” days. I had a script that would automate a workflow process that I did repeatedly: get files from a chosen folder and place them in named containers in a document created from a template. Part of the process involved Image Events, a little application that I used frequently in scripts.
My script failed. After a few hair-pulling minutes of debugging the script I discovered the problem was most likely Image Events. After all I had recently upgraded to Catalina (version 10.15.2). Sorry for that!
So I wrote a little test script in Script Editor:
set selected file to (choose file) tell application "Image Events" launch set openedFile to open selectedFile if openedFile is not missing value then close openedFile end if end tell openedFile
When I ran the script, I chose the image file, and checked the result for the openedFile variable. The value was missing value. Expletive!
Not wanting to process the files in the folder manually I then thought about Automator. Would it work? Or was it also broken.
There are those who say that Automator is a dead application “Whatever you can do in Automator you can probably do it faster or easier in another application” was one opinion.
For sure, there are batch processes available in some applications. For instance Photoshop has Image Processor, a script found under Files > Scripts. But I wanted something “quick and dirty” that converted screen grabs from 144 dpi to 300 dpi.
Launch Automator. Within minutes I had a folder that converted the files when dragged into it. This was due to a little Folder Action that was attached to it.
Since those who read my blog already know AppleScript, I felt it necessary to do a blog or two to introduce the application to those who may not be using it already.
Automator is a little application that comes bundled with your Macintosh. It has now graduated to the Applications folder. (On older OS versions it is tucked away under Utilities with Script Editor). Drag its icon to the Dock if you think you might want to play with it–and maybe enjoy working with its now upgraded interface.
When you run Automator the first hurdle is to decide what you want to create.
New project screen presents a number of workflow types you can create with Automator.
Interesting! Apparently you can make your own Image Capture Plugin. Then there is Dictation Command for voice commands and Quick Action for adding Services to the OS contextual architecture. But we are interested in a Folder Action quick fix.
When you click on the Folder Action icon, a description window opens. It informs you the obvious that a Folder Action is a workflow attached to a folder. When items are added to the folder the workflow created runs providing input to the Actions you have added to your workflow. Click the Choose button.
Yes, you will need a folder to attach your workflow, so pop into the Finder and create a folder on the Desktop named appropriately. We will name ours Scale 48pct. (Reducing the size of a 144 px image at 48 percent creates a 300 dpi image). Inside the folder we will create another folder named Processed. Easy enough.
Your folder for the Folder Action can be created anywhere, but the Desktop is an obvious choice.
Now back to Automator. At top right you are prompted “Folder Action receives files and folders added to”. For this you could stick with Choose folder but click on the arrows to the right and select Other…
Clicking on Other… opens the system Chooser from which you can select the folder you just created.
To the left of the Automator interface are two columns: Library and a list. Actions are grouped into classifications within the Library. The list of Actions to the right changes depending on what is chosen in the Library. Not having an idea of where to look, instead type scale in the search field at the top.
Since the purpose of the workflow is to scale images, double click on the item that reads Scale images. This pops up a dialog:
You may not want backups created by default. You can always Option-drag the files into the folder.
For simplicity, choose Don’t Add.
You now have the option to either scale the images by size (which sizes image proportionally based on the largest image dimension), or percent. You want percent. That’s it; well enough for testing.
Save your workflow: File > Save. Name your workflow in the dialog that opens.
Now test it. Option drag an image into the folder. Open the folder and get its file information (select the file and use Command+I). Still not convinced, compare its size to that of the original. (You did have the option key down when you dragged the image to the folder.)
The original idea for the workflow was to have the scaled image go into the folder named Processed once completed. Add another Action to your workflow.
Type in the word move into Automator’s search field. Double click Move Finder Items.
The Move finder Items action will now be added to your workflow.
You now have two actions in your workflow. Click on the double arrow to the right of Desktop in the to: field and choose Other from the list of options. Navigate to your Processed folder and click Choose.
If you want the processed files to replace the existing ones (which I don’t) check that option.
Save your workflow. This time drag a bunch of files to the folder.
Open the folder. Your resized files are in the Processed folder.
Imagine having a folder with a bunch of folders with a Folder Action to automate file processing or whatever.