Here's a thing that's been annoying me for a long time: Using OS X 10.6, when you navigate through folders, expanding them to see their content, you sometimes want to create a new folder at the bottom of the file hierarchy.

Consider this example:

some
└── nested
    └── folder

Now, having selected "folder", pressing N results in the new folder being created at the top of the visible hierarchy, i.e. the currently open Finder element (which in my case is "test"):

├── some
│   └── nested
│       └── folder
└── untitled folder

This is not what I need. I will manually have to move the "untitled folder" to its target parent, which is hard to do if you 1) don't want use your mouse, 2) can't CutPaste a folder like in Windows and 3) the current folder contains a lot of elements.

What I need is:

some
└── nested
    └── folder
        └── untitled folder

The new folder should be created in the folder that I currently selected (i.e. "folder").

Note that:

  • I want this to be done with a keyboard shortcut. I don't use the mouse that often.
  • I don't want to use any other Finder view (e.g. Columns)

Is there any way this could be achieved?


I know the Automator action "New Folder", but it copies the selected Finder elements into the target folder, and it's inserted at the wrong level. For example, selecting "folder", the result will be something like:

└── some
    └── nested
        ├── folder
        └── untitled folder
            └── folder
link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

Open Automator.app and create a new Service.

Set it to receive "no input" and then drag Run AppleScript from the actions pane to the workflow pane:

enter image description here

Now, paste the following in:

--try
tell application "Finder"
    if insertion location as alias is desktop as alias or {icon view, column view} contains current view of Finder window 1 then
        tell application "System Events" to keystroke "n" using {shift down, command down}
        -- faster than clicking menu bar items
        return
    end if
    try
        set p to item 1 of (get selection)
    on error
        tell application "System Events" to keystroke "n" using {shift down, command down}
        return
    end try
    tell application "System Events" to key code 124 --right; in case the selected folder isn't expanded
    try
        set fold to make new folder at p
    on error
        set fold to make new folder at container of p
    end try
    set selection to fold
end tell
tell application "System Events" to keystroke return
--end try

The key code and keystroke events should work as expected (without adding a delay) with shortcuts using ⌘, ⇧, ⇧⌘ or no keys as modifiers.

Save the service, for example under "New Folder (nested)". You can now assign a keyboard shortcut to it under System Preferences » Keyboard » Keyboard Shortcuts » Services.


Some other actions (like Paste, View - as *, Show View Options and Enclosing Folder) are also anchored to the insertion location (the folder shown in the title bar), so it would be pretty hard to have the behavior changed consistently.

link|improve this answer
Your script had this result, but I changed it to do what I need (minor thing). Works as expected though :) – slhck Jul 13 '11 at 15:04
I modified the script so that it tries to create the new folder inside item 1 of (get selection) first. – Lri Jul 13 '11 at 15:18
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.