Summarizing the contents of files

    If you manage large numbers of text files, you may want to see a summary of the contents of a file. The Standard Additions dictionary (located in the Scripting Additions folder) includes the term Summarize that lets you do this.

    Open the Standard Additions dictionary for me.

    To see the syntax of the Summarize command:
    Locate the String commands suite and click "summarize."

    The Summarize command requires the text to summarize. You can provide the actual text, or you can provide an alias to a text file or a file specification of a text file, including the name of any folders you have to open to see the file. For example, a file specification might look like this:

    My Disk:Documents Folder:Text File

    You would probably want to use this command to summarize any file, so the script needs to let you pick which file to summarize. The following example uses two other commands defined in the Standard Additions dictionary:
    Read, located in the File Read/Write suite, which reads the contents of a file
    Choose File, located in the User Interaction suite, which displays a dialog box that lets you select a file

    Show me a summary script.

    This script lets you select one file at a time and displays the summary in the Results window in the Script Editor.

    You can also see the summary of several files, including those in folders, when you don't have the Script Editor open. The following example includes an On Open handler, so you can use it as a droplet script. To use this script, save it as an application, then drag files to it in the Finder. The script shows a summary of any text files you drop on the script.

    Show me a droplet script that summarizes several files.

 


Table of contents