Use Folder Actions to implement OS 9 folder auto-sorting

May 23, '03 10:04:00AM

Contributed by: Diggory

Back in OS 9, if you dropped a new file (extension/font/control panel etc..) on the Sytem Folder it would offer to auto-sort the file to the correct sub-directory based on the type of file. In Mac OS X, system assets and extensions are put in the Library directories. These directories do not auto-sort dropped files into the correct subdirectory.

With Jaguar's AppleScript Folder Actions, however, you can get your libraries to auto-sort some of the file-types that live there. All you have to do is enable Folder Actions (done through the AppleScript Menu Extra in Applications -> AppleScript -> script menu.menu). Then attach the script I wrote to your Library(s)

This script cannot auto-sort all filetypes - but can handle the following types:

Enjoy! PS just in case my mac.com page gets overloaded, the script is in the second part of the hint, too.

The script (robg adds: Any formatting errors are mine, introduced when trying to narrow the display width a bit)

property SaverRecord : ¬
  {extension:"saver", description:"Screen Saver", directory:"Screen Savers"} ¬    
property prefpaneRecord : ¬
  {extension:"prefpane", description:"System Preference Pane", directory:"preferencePanes"}
property scriptRecord : ¬
  {extension:"scpt", description:"Compiled AppleScript", directory:"scripts"}
property serviceRecord : ¬
  {extension:"service", description:"System Service", directory:"services"}
property frameworkRecord : ¬
  {extension:"framework", description:"Framework", directory:"frameworks"}
property scriptingAdditionRecord : ¬
  {extension:"osax", description:"Scripting Addition", directory:"ScriptingAdditions"}
property aiffSoundRecord : ¬
  {extension:"aiff", description:"Macintosh Sound", directory:"Sounds"}
property ttfFontRecord : ¬
  {extension:"ttf", description:"TrueType Font", directory:"Fonts"}
property dFontRecord : ¬
  {extension:"dfont", description:"dFont", directory:"Fonts"}
property otfFontRecord : ¬
  {extension:"otf", description:"otFont", directory:"Fonts"}
property validRecords : ¬
  {SaverRecord, prefpaneRecord, scriptRecord, serviceRecord, frameworkRecord, ¬
    scriptingAdditionRecord, aiffSoundRecord, ttfFontRecord, dFontRecord, otfFontRecord}

--The handler for responding to when items are added to a folder: 
on adding folder items to targetFolder after receiving droppedItems
  
  -- set targetFolderAlias to targetFolder as alias
  repeat with currentFile in droppedItems
    
    tell application "Finder"
      set targetFolderName to the name of targetFolder
      set droppedFileName to the name of currentFile
      set droppedFileInfo to info for currentFile
    end tell
    
    repeat with currentRecord in validRecords
      if extension of currentRecord is equal to the ¬
        name extension of droppedFileInfo then
        
        tell application "Finder"
          set newTargetFolder to (folder named ¬
            (directory of currentRecord) of targetFolder)
          -- not sure about validity of next line... 
          if newTargetFolder exists then
            move currentFile to newTargetFolder
            display dialog " " & targetFolderName & ¬
              " has auto-sorted a " & description of currentRecord ¬
              & "." buttons {"?"} default button 1 ¬
              giving up after 3 --seconds 
          else
            display dialog ¬
              "the folder isn't there!" buttons {"OK"}
          end if
        end tell
        
      end if
    end repeat
    
  end repeat
end adding folder items to

Comments (13)


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