O'Reilly logo

AppleScript: The Missing Manual by Adam Goldstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deleting Files

So far, you've moved and copied files in the Finder from one place to another. There are some times, though, when you just want to get rid of a file—and AppleScript can do that too.

The key here is AppleScript's delete command. It works just like move or duplicate, except you don't have to specify where the deleted files should go (AppleScript automatically knows that deleted files should go in the Trash). Thus, a typical delete command would look something like this:

tell application "Finder"
    delete the file "Chihuahuas.doc" of the desktop
end tell

When you run this command—substituting the name of the actual file you want to delete, of course—you hear a satisfying clunch as the Finder wads up your file and deposits it in the Trash can. If you don't hear this sound effect, three things could be wrong:

  • You've muted your speakers. The fix: press the volume-up key or increase the volume in your System Preferences Sound Output tab.

  • You've turned off Mac OS X's sound effects. To turn them back on, visit System Preferences Sound Sound Effects tab and turn on "Play user interface sound effects."

  • You don't have a Chihuahuas.doc file on your desktop. Either get one, or replace Chihuahuas.doc of the desktop with the name of the file you want to delete.

An Example: Clearing Out Safari's Icon Cache

If you use Safari for a few weeks, visiting hundreds or thousands of Web sites, you'll probably notice a significant slowdown each time you load a page. That's caused, in part, by ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required