10.3. More on Working with Applications

In this section, you learn additional details about working with applications. You start by examining a program in the next Try It Out that's a little more sophisticated than those you've encountered so far in this chapter.

10.3.1.

10.3.1.1. Try It Out: Generating a List of Backup Files

This program shows how to use the Finder to create a list of files for backup that is then displayed as an HTML file in the Safari browser. The folder that is searched and the backup criteria used are hard-wired into the program. An exercise at the end of this chapter asks you to extend this program to increase its flexibility.

  1. Type the following program into Script Editor. Change the backupFolder variable to a folder on your system that contains some files you have modified within the last week.

    (*
     Create an HTML file that shows the files from your
     Documents folder that have been modified within the last 7 days
    *)
    set modifiedDays to 7 * days
    
    -- Change the following to a path to one of your folders
    set backupFolder to (path to documents folder as string) & "books:AppleScript:"
    
    set HTMLFile to (path to temporary items as string) & "backuplist.html"
    
    -- open temporary file and write a header to it
    
    set f to open for access file HTMLFile with write permission
    set eof of f to 0  -- truncate the file if it already exists
    
    -- write an HTNL header to the file
    
    -- Note: The following lines were entered with \r inside each string. The following
    -- shows how they appear ...

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.