newbie needs help wiht sorting/moving files

What I need to do is drop a CD/Disk onto a script and it then ask you for job information (this I have). Then I need to be albe to check all the files by creator type and move them to the correct folder. I am guessing the best way to identify the files are by the creator types? I am also guessing I will need a repeat code in there so it will check/move all the files.


on open (theFiles)
tell application "Finder"
activate
set folder_name to text returned of (display dialog "Enter the Folder Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
set job_code to text returned of (display dialog "Enter the Job Code:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
set the new_folder to make new folder at the desktop with properties {name:{folder_name & " " & job_code}}
open new_folder
make new folder at the new_folder with properties {name:(folder_name & " Fonts")}
make new folder at the new_folder with properties {name:(folder_name & " images")}
make new folder at the new_folder with properties {name:(folder_name & " Document files")}		
end tell
select every item of dropped
tell application "Finder" 
open droppeditems
if type = "8BIM" then move to folder (folder_name & " images")
if type = "XPR3" then move to folder (folder_name & " Document files")
if type = "ASPF" or "DMOV" then move to folder (folder_name & " Fonts")
end repeat
end open

Any help would be appericated.

Herb

A file’s ‘creator type’ associates it with a particular application. Its ‘file type’ identifies what kind of file it is - eg. text, application, data, etc. If you know that the files you want to move have all been made by the respective applications, using the ‘creator type’ should be fine.

Not with Mac OS - and possibly not with OS X either. You can just tell the Finder to move all the files with a certain creator type to the appropriate folder. This will be much faster than a repeat loop that tests each file in turn.

I’ve assumed here that all the files are at the root level of the dropped disk:

on open (theFiles)
  -- theFiles is a list of aliases. Check that only a single container has been dropped.
  if (count theFiles) > 1 then
    display dialog "More than one item has been dropped onto this script." buttons {"OK"} default button 1 with icon caution
  else if ((item 1 of theFiles) as string) does not end with ":" then
    display dialog "The dropped item is not a folder or disk." buttons {"OK"} default button 1 with icon caution
  else
    set source_folder to item 1 of theFiles
    
    tell application "Finder"
      activate
      set folder_name to text returned of (display dialog "Enter the Folder Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
      set job_code to text returned of (display dialog "Enter the Job Code:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
      set the new_folder to make new folder at the desktop with properties {name:{folder_name & " " & job_code}}
      
      set fonts_folder to make new folder at the new_folder with properties {name:(folder_name & " Fonts")}
      set images_folder to make new folder at the new_folder with properties {name:(folder_name & " images")}
      set docs_folder to make new folder at the new_folder with properties {name:(folder_name & " Document files")}
      
      move (every file of source_folder whose creator type is "8BIM") to images_folder
      move (every file of source_folder whose creator type is "XPR3") to docs_folder
      move (every file of source_folder whose creator type is "ASPF" or creator type is "DMOV") to fonts_folder
    end tell
  end if
end open

That woks great if you only have 1 folder your dropping onto it. In most cases there will be several folders and most likely subfolders, any ideas?

Herb

Hi, Herbie.

If in most cases you’re going to be dropping several folders (with subfolders) onto the script, it would obviously save everyone’s time if you said that in the first place rather than:

The following handles any number of dropped folders or disks, along with every subfolder in their hierarchies.

property fonts_folder : missing value
property images_folder : missing value
property docs_folder : missing value

on open dropped_items
  tell application "Finder"
    activate
    set folder_name to text returned of (display dialog "Enter the Folder Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
    set job_code to text returned of (display dialog "Enter the Job Code:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
    set the new_folder to make new folder at the desktop with properties {name:{folder_name & " " & job_code}}
    
    set fonts_folder to (make new folder at the new_folder with properties {name:(folder_name & " Fonts")}) as alias
    set images_folder to (make new folder at the new_folder with properties {name:(folder_name & " images")}) as alias
    set docs_folder to (make new folder at the new_folder with properties {name:(folder_name & " Document files")}) as alias
    
    -- Cycle through all the dropped items that are folders or disks
    repeat with this_item in dropped_items
      if (this_item as string) ends with ":" then my move_files(this_item)
    end repeat
  end tell
end open

on move_files(this_folder)
  tell application "Finder"
    duplicate (every file of this_folder whose creator type is "8BIM") to images_folder
    duplicate (every file of this_folder whose creator type is "XPR3") to docs_folder
    duplicate (every file of this_folder whose creator type is "ASPF" or creator type is "DMOV") to fonts_folder
    
    set subfolders to every folder of this_folder
    repeat with this_subfolder in subfolders
      my move_files(this_subfolder)
    end repeat
  end tell
end move_files