5.5. Deleting FilesSo 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 fileand 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 commandsubstituting the name of the actual file you want to delete, of courseyou 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:
5.5.1. An Example: Clearing Out Safari's Icon CacheIf 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 Safari's gigantic database of faviconsthose little icons you see in Safari's Address bar (Figure 5-6).
If you delete Safari's icon cache (which is stored in your Home Library Safari Icons folder), you can give Safari a significant speed boostand save a few megabytes of space while you're at it. Here's a script to automate the process: tell application "Finder" delete folder "Icons" of folder "Safari" of folder "Library" of home display dialog "Would you like to empty the trash now?" (* If you click Cancel in the dialog box, the script ends here. Otherwise, it continues to the next line *) empty the trash end tell When you run the script, the Finder drops the Icons folder in the Trash, and then presents the dialog boxes shown in Figure 5-7. The only other time you'd really use the delete command is when you have a folder that needs to be emptied regularly (like your Decade-old Home Videos folder, for example). Besides that, there's not much use for delete, since you can always achieve one-time erasures by choosing File Move to Trash (or by pressing -Delete) in the Finder.
|