Collect files in new folder via AppleScript and a plug-in

Dec 30, '08 07:30:00AM

Contributed by: Michael_Ng

The Group in New Folder script in the Big Cat Scripts Plug-in was my favorite Finder tool for a long time, and I was very upset when it was broken in Leopard. I have managed to hack togather something that can be activated using AmScriptsCMX(UB).

Here is my script. To use it, first nstall AmScriptsCMX(UB) and put the below script in ~/Library/Scripts.

tell application "Finder"
  set theList to the selection
  
  if the theList is {} then
    beep
    display dialog "No files or applications are selected."
    buttons("Cancel")
  end if
end tell

tell application "Finder"
  
  set thename to (text returned of (display dialog "New folder with name:" default answer ""))
  set theLocation to the target of Finder window 1
  repeat
    if thename is in (the name of every item of theLocation) then
      set thename to (text returned of (display dialog ("An item with the name "" & thename & "" already exists." & return & "Please enter a new name:") default answer thename))
    else
      exit repeat
    end if
  end repeat
  set newFolder to (make new folder with properties {name:thename} at theLocation)
  try
    move theList to newFolder
  end try
end tell

Warning: I am not an AppleScript wizard; this script works for me as is, though. Usual disclaimer applies. Please do let me know if this script can be improved. Thanks to part of this hint that I referred to, and also to BigCat's original script, for making the revised version possible.

Comments (3)


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