Create Multiple Folders Based on List/Text-File

Hi everone!

I need to create multiple folders based on a list of addresses.
I have the list in excel/text file.

I tried several things, but I cont figure out how to tackle this matter.

Anyone can help me?

@TomP, welcome to Keyboard Maestro (KM) and its Forum.
KM is one of the best Mac automation tools available, the its Forum is one of the best and friendliest forums on the Internet. Whenever you reach a tough stumbling block trying to use KM, please feel free to post your question/problem here for help.

You will also find this helpful:
Tip: How Do I Get The Best Answer in the Shortest Time?


See this topic, which is very similar to yours. It provides a macro solution.

1 Like

JM, I tried posting a reply to this message, it ended up in the wrong folder. So I deleted it there and then tried pasting it in here. The website wouldn't let me because my post was "too similar to a post I posted elsewhere". That's quite funny. Oh well. I've got it saved but I don't know how to post it now.

[EDIT: Added the post below - PeterNLewis]

I'm not sure what you want because an address can look like this: "33-110 Smith Ave W." Do you want a folder name that contains that string as the name? Including the punctuation? Seems dangerous. Addresses can contain really weird characters and some characters may not be permitted in folder names. So I'm not sure if you really want that. You may want to change the question.

But if the problem is exactly as you've described it, you can do it in two actions. It would look like this: (but I advise you not to do this until the questions has been clarified)

I had to assume a path below because you didn't specify one.

My macro below is meant to give you ideas. It is not meant for you to download and run, because it contains assumptions that won't work for you and it doesn't detect/prevent certain kinds of errors.

Keyboard Maestro 8.2.4 “Make folders” Macro

Make folders.kmmacros (2.1 KB)

Hi Sleepy,

Thanks for your help.
I have made a clean list of address details, without punctuations etc.
I then saved it in a text file, and had the macro : the lines in file". That didn't work.
Now I tried to put it in a text, see below. Still no succes. Any tips?

Let me give that a try. Of course, I won't be testing Dropbox since I don' t have that.

I typed that script in. It works for me. Why doesn't it work for you? I suggest you do not include Dropbox in your initial tests as I have no idea how that works.

I suggest using this as your path:

mkdir ~/$KMVAR_VarName

which puts it into your home directory. That's the default directory for a Terminal window, at least for me it is. In your case use NewName of course.

Hey Tom,

Welcome to the forum!  :smile:

My best guess is that you don't have a complete directory chain – e.g all folders must exist all the way to the target folder.

The way around this is to use the -p switch for mkdir as I do in my example macro below.

This creates the enclosing folders as necessary.

Note too that I've double-quoted "$KMVAR_nameStr". While these are only necessary if you have spaces in the name-string, it's a good habit to get in to – because somewhere down the line you'll get bitten if you don't have them.

This macro should just work out of the box, but do let me know if you have any problems or questions.


Make New Directories from List v1.00.kmmacros (6.0 KB)


Hey Guys,

I suggest you never, ever test shell scripts using any directory you can't afford to lose.

Always test with a throw-away test directory, and only switch to your working directory once you have your script working.

This is true even for seasoned professionals.

While mdir is non-destructive, there are more than a few ways to cause a catastrophe when shell scripting.

Actually a better way to write my script in my macro would be:


printf "$newDirPath" # Uncomment to show the string, and comment-out the `mkdir` line.

# mkdir -p $newDirPath

This allows me to display my constructed path, before I enable the mkdir line to run.

To do this I'll normally change the output of the Execute a Shell Script action to “Display in Window”.


1 Like

Thanks Chris,

For your help. This does the trick for me.
Indeed, I experienced problems with spaces before your macro. Now it all works fine!


Your advice was wiser than mine on at least two points. I'll try to adapt to that advice.

Would I be able to change this (mkdir -p ~/Dropbox/Documenten/Example/"$KMVAR_nameStr") to make the path relative to my front window?

So if I'm inside a folder called TESTS on my DESKTOP, KM would automatically create the following path:
mkdir -p ~/Desktop/TESTS/"$KMVAR_nameStr"

So wherever I am in Finder, KM would grab that path and use it on that Shell Script section.

Another request:
Instead of having a pre defined list inside KM, when setting the "dirNameList" variable, is it possible to use what's on the clipboard? So if I select a text and hit COPY, now that list is on my clipboard and I would just run the macro using a shortcut and the list on that variable would use the clipboard content.

UPDATE: I just saw this thread and will be reading and watching your video to see if I can make it work for my macro - Add Clipboard Lines to a Variable - #14 by ccstone
Maybe I will just need help with the path issue

Why just make one folder from the Clipboard when you can make multiple folders if desired?

  • The For Each Action page tells you that you can use "Lines In Collection"
  • The Collections page tells you that you can use "Lines In"
    • The Lines In page tells you can use lines from the Clipboard
    • The Tokens page has FinderInsertionLocation whose page states "...which is usually the path of the front window."
  • There's a New Folder action
  • The only tricky bit is that FinderInsertionLocation doesn't include the trailing slash, so you have to add that and then add your folder name

Putting all that together:

One folder...? I guess you misunderstood my request.
What I'm looking for is a way to select multiple folders and hit COPY to send that list to the clipboard. Once on the clipboard, then I run the macro. So instead of going to KM to paste that list into the variable, the macro does it automatically based on the clipboard's content. Hope it makes sense now.

I need to spend some time reading what you just explained and perform some tests. I will get back to you once I do that and hopefully have some good news to share :wink:


I started with a "this is how you make one folder using the Clipboard to name it", then moved on to "or use a Collection to make multiple folders". Then decided the first section was redundant and cut it out -- but forgot to remove that line!

Apologies for the confusion...

That action does just what you asked for -- uses one or more lines of text on the Clipboard to make one or more folders in the currently active Finder window, each folder named using a line in the Clipboard. But do take a moment to go through those linked manual pages -- I'm finding that "For Each", "Collection" and combinations of tokens are both powerful and quite easy to put together once you know where to look to find out what you need.

I believe this still works:

Create a nested folder structure based on a plain text outline - Macro Library - Keyboard Maestro Discourse

For your purpose you can just specify an unindented list (no subfolders, unless you need any)

An updated version (code refreshed, reporting behaviour slightly simplified) here:

Create a nested folder structure based on a plain text outline - Macro Library - Keyboard Maestro Discourse

1 Like

Apologies for dragging this one back out but, how would I account for spaces in the folder names? For example: "2018 - 01 - January". I've tried escaping the space but it just stops.

Hey Martin,

You don't mention what macro you're referring to...

My macro above properly accounts for spaces.