Create a New Folder With The Finder Selection

Hi All,

KM newbie here, having a bit of trouble figuring out this fairly simple workflow:

  • Select all items in a folder with "XX" in the filename
  • Create folder with selected items
  • Rename folder "Y"
  • Move folder + contents to parent directory

I'm honestly stuck at the first point. Any thoughts appreciated!

Hi @mftr,

The workflow you describe sounds like what you would do if you were to perform these steps manually. There's nothing wrong with that, but we can accomplish this same goal more efficiently with KM, like so:

  • Create folder "Y" in parent directory
  • Move all items in designated folder with "XX" in the filename to folder "Y"

Using the desktop as the parent directory, here's an example macro that shows how this can work:

Example Macro.kmmacros (2.7 KB)

Hopefully this should get you started. If you have any specific questions about how this macro works, feel free to ask.


Hey @mftr,

If I've understood your requirements correctly this should do the job with any selection in any folder.


Finder -- Enclose Selected Items in a New Named Folder- and Move Them to the Parent Folder.kmmacros (5.6 KB)


Thanks guys! They worked great! I definitely appreciate the two different approaches :slight_smile:

Tagging along on this question. I have trouble getting these to work.
What I do repeatedly is:

  • select files within a folder (different folders all the time)
  • Creating a new folder based on the selection
  • naming the new folder the same every time within the original folder

I can't understand the path that I need to write in the 'Create New Folder' action

Hey Thomas,

My script in post post #3 does just that.

All you have to do is change the name of the new folder and remove or comment-out the move to parent folder line.

I've added a newFolderName property and commented-out the move to parent line in the following AppleScript:

# Auth: Christopher Stone
# dCre: 2018/09/07 10:02
# dMod: 2022/10/07 00:04
# Appl: Finder
# Task: Enclose selected item in a new named folder, and move them to the parent folder.
# Libs: None
# Osax: None
# Tags: @ccstone, @Applescript, @Script, @Finder, @Enclose, @Selected, @Item, @New, @Named, @Folder, @Move, @Parent
property newFolderName : "Your New Folder Name"

   tell application "Finder"
      set finderSelectionList to selection as alias list
      set parentFolder to parent of (get item 1 of finderSelectionList)
      set newFolder to make new folder at parentFolder with properties {name:newFolderName}
      move finderSelectionList to newFolder
      # move newFolder to parent of parentFolder
   end tell
on error e number n
   set e to e & return & return & "Num: " & n
   if n ≠ -128 then
         tell application (path to frontmost application as text) to set ddButton to button returned of ¬
            (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to e
      end try
   end if
end try


If you want to use Keyboard Maestro's native actions to do this you'll need.

Grab the parent path on the first pass through the loop.