Ask Mac Automator: Triggering a Folder Action

I don’t suppose it’s possible to share a macro for using KM to create and send an email based on a file being present in a particular folder? BTW loving the site! —Mark
It’s always a pleasure to receive Ask Mac Automator questions, because they give me an idea of the workflow needs of my subscribers, and it sometimes a provides a challenge to research and answer the questions. In this case, the question was easy to answer. Thanks, Mark, for asking it.
This Keyboard Maestro workflow involves using a folder trigger to trigger an action.

Macro Setup

Keyboard Maestro has over a dozen triggers that in turn trigger other actions. So for example, you can assign a keyboard shortcut trigger or a time trigger to trigger one or more actions.

For this particular action, we need a Folder Trigger, which is triggered when a particular file is added to the folder.

So in a new macro, you select the Folder Trigger from the drop-down under “Trigger by any of the following.”

After adding the trigger, you need to point to the folder that you want KM to watch. Keep in mind, that this trigger will fire each time a file is added to the specified folder. (Note: as you can see in the screenshot below, the trigger can also be set to fire when a file is removed or when a file is added or removed.)
For this particular workflow, you may need to create a folder that is only used for this macro. I will show later how the folder action application, Hazel, can be used for specific files added to a folder.)

Mail Action

The second part of the action is to send a preset email when a folder is added to the specified folder. Keyboard Maestro contains an action for just that purpose.

In the macro editor, you do a search for “Send a Mail” or click on the Notifications folder inside of Actions to locate it.

In the email action, fill in the appropriate information, and select to have to have the email sent immediately after the folder trigger occurs, or to open the email in Mail.

If you plan to have the email sent immediately, then you should test the action to make sure everything is set up properly.

That’s it for this Keyboard Maestro workflow. The automation if used to fullest extent, will trigger the actions without you have to do anything else. It’s what I call a trigger-less action.

Hazel Approach

Using Hazel, you set up a folder action that fires when a particular file is added to a folder. This folder action in turn can fire the Keyboard Maestro action we created. The following instructions assume that you have a basic understanding of how Hazel works.

In order to do this, you will first need the AppleScript script for the KM action. Grab the scrip by clicking the “Or by script” under the Trigger part of the macro. Select “Apple Script” and copy that.

 

Now open Hazel, and add the folder you want to trigger the action.

Next, assign the Hazel trigger a name, set the rules for the trigger, and then select Run AppleScript from the drop-down under “Do the following to the matched file or folder.” Where it says “embedded script,” click on the Edit script button and paste the KM script in there.

Hazel runs that script when the specified file is added to the assigned folder. This is called mapping one application to another.

Your Automation Question

You are encouraged to send your own automation question to me, and if I can answer it, I will may post your question and my response as a blog post for which other readers may find useful.

I also accept guest blog posts about Mac automation. Use the contact form to send your question, or send you idea for an article.

>
GET ACCESS TO SUBSCRIBERS-ONLY  Mac Automation Resource Library
x
%d bloggers like this: