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

Moving Files Around

Being able to display your files is useful, but it's only half of what the Finder can do. The other half, of course, is to move your files—putting them in a new folder, deleting them, and so on. With AppleScript, you can automate these actions and more.

Transferring Items from One Folder to Another

The simplest action you can perform on a file is dragging it from one folder (or disk) to another. With AppleScript, it's also one of the simplest actions you can control in the Finder.

The key to this trick is the move command. It's part of the Finder's Standard Suite (Section 3.2.3), so it's a pretty common command. And, as the Finder's dictionary explains, the move command follows this simple structure:

tell application "Finder"
    move someItem to somePlace
end tell

Note

In this example, someItem can be either a single item or a list of items. That makes the move command perfect for transferring whole clusters of files (or folders) in a single step. (See Chapter 6 for the lowdown on lists.)

And also, if you use the move command to transfer files from one disk to another, AppleScript (like the Finder) assumes that you mean to copy the files. If you want, you can then use the delete command (Section 5.5) to erase the files from the original disk.

Now, if you're the sort of person who always saves downloads and email attachments to your desktop, you've probably noticed your desktop getting pretty full. You might have so many icons that you've had to shrink them down (View ...

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