Move selected items into ready-to-rename folder

Apr 02, '09 07:30:00AM

Contributed by: barryels

This is a simple AppleScript for the Finder which moves the currently selected items into a newly-created folder, and puts the new folder into rename mode. I use this to quickly sort my files into properly-named folders.

(*
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
After saving the script, you'll want to use a keyboard shortcut tool (I use Spark) to run this script via the keyboard -- I've set the key combo for this one to Command-G.

[robg adds: This worked as described in my testing.]

Comments (19)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090331002620633