property minLevels : -1 property indentation : " " -- set this to whatever you want to indent with -- setup on setup() set minLevels to -1 tell application "Scriptable Text Editor" activate make new document at beginning end tell end setup -- finish on finish() -- no clean up needed for this script end finish -- drag-and-drop interface on open fileList setup() repeat with aFile in fileList processFile(aFile) end repeat finish() end open -- launch interface (assumes launch doesn't disturb finder selection; -- e.g., script may be launched from Automated Tasks menu) on run setup() if (count of application "Finder"'s selection) is 0 then activate set aFile to choose folder with prompt "Select a folder to process:" tell application "Scriptable Text Editor" to activate processFile(aFile) else repeat with aFile in application "Finder"'s selection processFile(aFile) end repeat end if finish() end run on processFile(pFile) Traverse(pFile as text) end processFile on Traverse(pFolder) handleOneFile(pFolder as text) tell application "Finder" set folderContents to list folder alias pFolder repeat with x in folderContents set xName to (x as string) set xAlias to alias (pFolder & x) if kind of xAlias is "folder" then -- recurse to handle nested folder Traverse(xAlias as text) of me else handleOneFile(xAlias as text) of me end if end repeat end tell end Traverse -- This routine is given the full pathname of each file in the hierarchy. -- In this example, it converts the first parts of the pathname to some -- indentation, then stuffs it into a Scriptable Text Editor document. -- You can replace this functionality with anything you need to do to -- every file within a certain folder or disk. -- on handleOneFile(pFile) if last character of pFile is ":" then set pFile to (characters 1 through ((length of pFile) - 1) of pFile) as text end if set Parts to Parts(pFile) if minLevels < 0 then set minLevels to length of Parts end if tell application "Scriptable Text Editor" repeat ((length of Parts) - minLevels) times set selection to indentation end repeat set selection to (last item of Parts & return) end tell end handleOneFile -- break a pathname into parts on Parts(pPathname) set olddelim to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set mylist to text items of pPathname set AppleScript's text item delimiters to olddelim return mylist end Parts