Searching For Existing Folders

Hey guys,

Whenever I have a new client, I always create a new folder on my computer, and depending on the type of project, I place certain folders/template files inside.

I've already created a macro for this that works, but where I'm stuck is for when I have repeat clients.

I need to add a condition to first search my drive to see if a folder name already exists with the client's name. If it does, I want it to create certain subfolders for their newest project. If it doesn't, then I want it to create a new folder for the client.

How would I go about doing this? Is there a specific action step I should use?

Any help would be appreciated.

Thanks!

1 Like

Hey Mike,

Welcome to the forum!  :sunglasses:

Scope this out.

-Chris


Using Spotlight From Keyboard Maestro v1.00.kmmacros (5.5 KB)

Macro-Image

Keyboard Maestro Export

Thanks for replying @ccstone

I imported this into KM and tried to run it but nothing happened. I'm not quite sure I follow what is happening with this macro.

Anything I should try in order to make this work?

Hey @mindovina,

  • You made sure the macro was enabled?
  • You made sure the macro-group was enabled?
  • You change the variable to an existing folder name that's in your ~/Documents folder hierarchy?

-Chris

@ccstone

The macro and the macro group were enabled.

The only thing I'm unsure of based on your post is what you meant by "You change the variable to an existing folder name that's in your ~/Documents folder hierarchy?"

The folder I want it to search is on an external hard drive.

Do I replace local_FolderName? with the name of my drive?

Or do I update something else in the section that says: mdfind -onlyin ~/Documents "kMDItemFSName == \"$KMVAR_local_FolderName\"cdw" ?

I'm not very knowledgeable on shell scripts so I'll wait for Chris to actually answer your question but I believe the file path in the shell script does need to be adjusted to point to your external hard drive.

The point about the variable just means you changed it to the name of whatever folder you wanted to search for and/or create.

-Also Chris

Hey Mike,

That's vital information that should be included in any help request...

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?

Version 1.0.1 of the macro has a dedicated Target Path variable for the search path and will accept a full POSIX Path or a $HOME-Based POSIX Path (often referred to as a Tilde-Path).

-Chris


Using Spotlight From Keyboard Maestro v1.01.kmmacros (7.0 KB)

Macro-Image

Keyboard Maestro Export

1 Like

Hey @ccstone

Sorry a lot of that went over my head. I'm guessing this means I can't use this macro with an external drive?

I'm a total n00b at this stuff.

Did you look at the macro? It demonstrates how to use an external drive.

  • Open a new window in the Finder.
  • Press Cmd-Shift-C.
  • Select the External Drive you want.
  • Press Cmd-Opt-C.
  • Paste the resultant path string in the correct variable in the macro.
  • Type the name of the folder you want to search for in the correct variable in the macro.
  • Run the macro.

This is the path string to my external test drive:

/Volumes/Firestorm

You'll get a pop-up window that looks similar to this:

image

-Chris

@ccstone Whoops. I totally missed the second macro. It seems like I've figured this out and have it working with my existing original macro. Thank you so much!

One last question... is it possible to change the shell script result text and/or have nothing pop up at all?

Take a closer look at the Execute a Shell Script action on the wiki.