Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Create a new folder in the current list-view directory' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a new folder in the current list-view directory
Authored by: Fenton on Nov 25, '08 09:10:05AM
I'm afraid the original did not work for me when I selected a file; I believe because the path is set to a string instead of an alias. I am on 10.4.11, if that matters. In any case, there is a shorter way to get the parent folder, using the class "container," which allows it to remain an alias (like current Path). I also used class to check whether the selection is a folder. I didn't have the problem needing quit for System Events, but I used the more usual AppleScript exit of "return." I don't know how to make the name selected at the end either :-]
tell application "Finder"
		set selectedItem to selection
		set currentPath to ((the first item of the selectedItem) as alias)
		if class of currentPath is folder then
			-- it is a folder
			set the parentPath to currentPath
			-- it is a file
			set parentFolder to container of currentPath
		end if
		set newFolder to (my createFolder(parentFolder))
	on error -- no folder or file is selected
		set the parentFolder to (folder of the front window as alias)
		set newFolder to (my createFolder(parentFolder))
	end try
end tell

on createFolder(folderLocation)
	tell application "Finder"
		set thisFolder to make new folder at folderLocation
		set selection to thisFolder
		tell application "System Events"
			keystroke return
		end tell
	end tell
end createFolder

FileMaker Developer
San Diego

[ Reply to This | # ]

Create a new folder in the current list-view directory
Authored by: dhjdhj on Jun 12, '10 04:18:09PM

I'm no expert on applescript (indeed trying to learn it right now) but that "as alias" does not seem to work correctly. In particular, I selected a folder and this script always seemed to create new folder at the same level as selected folder, not inside it.

I inserted the line
set foo to class of currentPath
and took a look at the value of foo. Its value is "alias" and so the test to see if "class of currentPath is folder" can never succeed as far as I can tell.

I'm sure I'll figure it out after reading a bit more about applescript but unless I'm missing something, I can't see how this script could ever have worked when a folder is selected.


[ Reply to This | # ]
Create a new folder in the current list-view directory
Authored by: dhjdhj on Jun 12, '10 04:29:37PM

The line

set the parentPath to currentPath

seems useless...... parentPath is not used anywhere (unless it's a special system variable that I don't know about yet).....however, changing parentPath to parentFolder actually fixes the problem (at least in the case where the selected item was a folder, which is all I care about)

Hope this helps others.

[ Reply to This | # ]