(*
Move items into new folder
Author: Barry Els
Version: 1.1
*)
tell application "Finder"
try
set theSelection to selection
set currentPath to ((the first item of the theSelection) as alias)
set parentPath to currentPath
if (currentPath as string) ends with ":" then -- it is a folder
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set the parentPath to (text items 1 thru -3 of (currentPath as string)) as string
set AppleScript's text item delimiters to od
else -- it is a file
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set the parentPath to (text items 1 thru -2 of (currentPath as string)) as string
set AppleScript's text item delimiters to od
end if
try
set newFolder to (my createFolder(parentPath))
move theSelection to newFolder
delay 0.1
set selection to newFolder
tell application "System Events"
keystroke return
quit
end tell
end try
on error
(*
no folder or file is selected, warn the user
*)
display dialog ("Please select one or several items to group" & (theSelection as string))
end try
end tell
on createFolder(selectedPath)
tell application "Finder"
set createdFolder to make new folder at selectedPath
end tell
return createdFolder
end createFolder