How to create new folder with a custom name?

Hi,

First time user of Keyboard Maestro. I've managed to open Terminal, cd to a folder, and execute a simple mkdir new-project-name...

But, how do I set a prompt to insert a custom folder name?

I can see the potential in this app to really improve my workflow!

Keyboard Maestro 8.2 “New Project” Macro

New Project.kmmacros (2.6 KB)

Since you started off doing this by way of Terminal, here’s how you would complete the bash script to retrieve user input and utilise this for the name of a new folder being created:

cd /Users/stephen/Repositories
echo -n "Enter new folder name: "
read new_project_name
mkdir $new_project_name

All of this can go into a single Execute in Terminal action, as opposed to having one action per command and using a Pause in between.

If I may ask, is there are specific reason you chose to use the Execute in Terminal action to accomplish this ?

Hi, thanks for the reply.

I have a little bit of experience with Terminal, would you recommend an alternative solution?

I added the bash script, but it's not working?

Hi,

This works. But, is there a way to pause the macro until a new folder name is provided and the return key is pressed? At the moment I've added a 7 second delay to get this working.

bigImage

I try avoid using Terminal, or Shell Scripts in KM, because sometimes the smallest error (typo) can result in disaster.

I just uploaded a macro I've been using for about a year now that does exactly what you ask for:

MACRO: Create New FOLDER in Current @Finder Folder

Please feel free to post in that thread any questions, issues, and/or suggestions that you might have about the macro.

My apologies, Stephen, it's because I don't have the Execute in Terminal action for some reason (was this a third-party add-on?), so couldn't test it precisely in the same way. But the reason it didn't work is because there ought to be semicolons terminating each command line:

cd /Users/stephen/Repositories;
echo -n "Enter new folder name: "; 
read new_project_name;
mkdir "$new_project_name"

There should also be double quotes surrounding $new_project_name as an argument of mkdir to handle folder names with spaces:

But, the reason I asked why you were choosing to use this particular action to do this is because Keyboard Maestro provides the means with which to create folders in Finder:

1 Like

Hi Stephen,

it seems you are using an old version of my “Execute a Script in Terminal” plugin. Go here for the latest version, which allows you to use KM variables and is also updated for KM8. [1]

But for your purposes here you don’t need that plugin (unless I’m misunderstanding). It works better with the KM standard action “Execute Shell Script”:

27-pty-fs8

(The sole purpose of my Execute in Terminal plugin is to run a shell script open in the Terminal, as opposed to the “normal”, hidden shell.)


[1] Before you download a macro or a plugin from a thread on the forum, it is always a good idea to scroll down towards the latest post in the thread of that macro/plugin. This is because when the author of the macro/plugin posts an update after a couple of weeks or so, he is no longer allowed to modify the original post. Hence you’ll find the latest versions of macros/plugins often in a separate, later post on the thread.

You find third-party (user-made) plugins in the Plugin section of this forum.

The plugin used by Stephen is this one.

1 Like

Hi CKJ and Tom,

Thanks for responding to my post.

I downloaded Keyboard Maestro from the website, I’ve not installed any plugins - I’m just using the stock version of the software.

I’m still finding my feet with the software, so I’m most likely not using the best actions for what I’m trying to do.

I have a plan to create a much bigger action, for a set of tasks I do on a fairly regular basis. Part of that involves installing software via the Terminal.

It would be useful to know if an action can be paused until the return key is pressed.

This would allow me to remove the 7 second pause from my current macro.

Is that possible?

Yup, this is actually quite easy. Just add a Pause Until action configured like this after the action you want to pause on:

03 PM

Great, thanks! I spotted that action last night, but I didn’t notice the dropdown menu to the right of the text box.

Hi,

I couldn’t initially get the action to work when the new folder name had any white space. test project output 2 folders, test and project

Your tip to add double quotes around the variable "$new_project_name" did the trick. However, for some reason when I typed the double quotes they didn’t work.

Not sure if it’s a setting on my Mac, or in Keyboard Maestro, but double quotes get converted to smart quotes - which doesn’t work. I had to copy and paste the quotes from your example.

Thanks again!

Here's my working macro incase anyone wants to take a look. It's not perfect (yet)

But it works, and it now also creates a subfolder in the new folder.

Thanks to CJK, Tom and gglick for the support.

New Project.kmmacros (3.8 KB)
bigImage

this prompts the user for the folder name and then creates the folder using the terminal
it works with spaces on the name as well