--hubionmac.com 05.09.2009
tell application "Finder"
set myfolder to container of ((item 1 of (selection as list)) as alias)
set folderlist to (name of every container of myfolder)
end tell
set selectionNames to getSelectionNames()
set folderlist to BubbleSort(folderlist)
set folderlist to {"----NewFolder----"} & CheckupLists(folderlist, selectionNames)
tell application "Finder"
set theaction to choose from list folderlist default items {item 1 of folderlist}
if theaction ≠ false then
if theaction as text = (item 1 of folderlist) as text then
set foldername to text returned of (display dialog "New folder name?" default answer "new folder")
set thefolder to make new folder at myfolder with properties {name:foldername}
move selection to thefolder
else
move selection to folder (theaction as text) of myfolder
end if
end if
end tell
on BubbleSort(theList)
if class of theList is list then
set theSize to length of theList
repeat with i from 1 to theSize
repeat with j from 2 to (theSize - i + 1)
if ((item (j - 1) of theList) > (item j of theList)) then
set temp to (item (j - 1) of theList)
set (item (j - 1) of theList) to (item j of theList)
set (item j of theList) to temp
end if
end repeat
end repeat
return theList
else
return false
end if
end BubbleSort
on getSelectionNames()
tell application "Finder"
set b to {}
repeat with a in (selection as list)
set b to b & name of a
end repeat
end tell
return b
end getSelectionNames
on CheckupLists(folderlist, selectionNames)
set ff to {}
repeat with f in folderlist
if selectionNames does not contain f then
set ff to ff & f
end if
end repeat
return ff
end CheckupLists