Macro to Check if Item Added to a Folder Is a Folder, and Then Pass the Name of That Folder to a Script

Hi all - when I get a new client lead in my CRM, Zapier triggers an action to create a new folder in my work dropbox in the name of the client that stores all files related to that client, in a folder called 'Leads'

When I confirm that client is now a paying client, zapier creates a new folder in a different folder called 'Clients', again, in the name of the client.

Some clients are onboarded so fast that we never get to creating a record for them in the CRM before they become clients, so this folder creation is useful.

But for clients who already had a folder with relevant files in it, it's a duplication.

What I'd like to do is have KM monitor the Clients folder, and whenever a new folder is created, it checks that there isn't a folder with the same name already in the Leads folder, and if there is, move it the Clients folder, replacing the existing folder that's just been created by Zapier.

I have used an applescript in Hazel to do this, triggered if Hazel had itself first confirmed that the item added to a folder was a folder, as opposed to a file, but I'm struggling to see how I can replicate this in KM!

Hey @Dave_Boyle,

Welcome to the Keyboard Maestro Forum!  :smile:

Personally I think if you're already using Hazel for this you should stick with it. Hazel is purpose-built for that sort of thing and is therefore superior to Keyboard Maestro in performing those kinds of tasks.

That said – you should be able to make Keyboard Maestro do the job if you're willing to work at it.


Folder Watcher.kmmacros (1.5 KB)

Can't you use the same AppleScript in KM?

If you want to know if the item added to a folder is a folder, you can use the Get File Attribute action (which also works with folders) and get the "file type" attribute.
If the item is a folder, this will return "directory".


you can pass the KM Variable "Local__ItemPathFromFolderTrigger" to your AppleScript using this:

### Requires Keyboard Maestro 8.0.3+ ###
set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set folderAddedPath to getvariable "Local__ItemPathFromFolderTrigger" instance kmInst
end tell