Chapter 5. Controlling Files

Most people have a love-hate relationship with their computer. Sure, your Mac is a great tool for when you want to edit images or video, send and receive email, or play Halo. But your computer also serves as a digital file cabinet: a place where you can create and store files, move them around, organize them in folders, trash them when they’re no longer needed, and copy them to another disk or computer on the fly.

Files, of course, are nothing more than individual packages of information that you keep on your hard drive. But for all the filing tasks they perform, most computer users tend to handle files manually: drag this file here, create a new folder there, and so on. After a while, these mundane tasks are what make people start to hate their computers.

If you’re sick of dealing with your files one at a time—and taking up half your day in the process—there’s no better tool in your arsenal than AppleScript. By commanding the Finder, AppleScript lets you:

  • Move all the files off your desktop in one fell swoop (Section 5.3.1.3)

  • Back up an important folder to a separate hard drive, just in case your computer dies (Section 5.4.1)

  • Rename all the files in a folder—without having to type their new names individually (Section 6.4.1)

For these jobs and more, AppleScript can save you annoyance, tedium, and—most of all—time.

Note

The example scripts from this chapter can be found on the AppleScript Examples CD (see Sidebar 2.1 for instructions).

File Path Boot Camp

The ...

Get AppleScript: The Missing Manual 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.