Name

Finder Commands

Dictionary commands

computer constant or string

The computer command provides information about the machine running the script. The following example displays how much memory is available in megabytes, including virtual memory. This command is the AppleScript equivalent of the Gestalt function that is part of the Macintosh Application Programming Interface (API). You can find out more about this function at http://developer.apple.com/techpubs/mac/OSUtilities/OSUtilities-11.html.

You can use the following constants with the computer command: CPU, FPU, hardware, memory available, memory installed, MMU, operating system, and sound system. There are also numerous other selectors that you can use instead of these constants, as long as you know the four-character string and what its return value means (an integer). For example, the command computer "scr#" tells you how many active scripting systems the computer has, and computer "sysa" indicates whether the computer is a PowerPC (result value of 2 means yes).

tell application "Finder"
   set mem to (computer memory available)
   display dialog (mem / 1024 / 1024)
end tell
duplicate reference to object

Duplicate an object like a file or folder with code such as:

tell application "Finder" to duplicate folder "today" to folder¬
   "actions" of folder "desktop" with replacing

This code will take the “today” folder on the desktop and duplicate it (reproduce it and its contents) to a desktop folder called “actions.” This code will also replace any “today” folders that are contained by the “actions” folder. This is a good command to use when you are backing up files from one volume or disk to another.

make

You can make a new element of the Finder (like a folder or text or image file) with this powerful command. This is a useful command for such tasks as creating a log file and a folder to contain that log. This example creates a new BBEdit text file called “theLog” on the desktop:

tell app "Finder" to make file at desktop with properties {name:¬ "theLog",
creator type: "R*ch", file type: "TEXT"}

If you leave out the at location part when making a new file or folder, then the Finder will by default make the new file or folder on the desktop. The return value of the make command is the object that you created. The “Finder” code sample beneath the "with properties record" section stores the new folder in a variable and then makes a new file in that folder in the next line, using the folder variable as the new file location.

move reference to object

You can move files and folders around to new locations using this command. Unlike duplicate, this command does not create a copy of the object and leave one copy in the original place; it moves it to the new location. This script moves a folder from the desktop to inside another desktop folder called “actions.” The script also positions the folder to a spot 10 pixels from the left edge of the parent folder and 10 pixels down from the “actions” folder’s top border. The exception is moving files or folders from one disk or volume to another; this copies the original items to the new locations and leaves the originals intact:

tell application "Finder"
   activate
   move folder "LogFolder" to folder "actions" positioned at {10, 10}
end tell
to location reference

This is a required parameter specifying where you want to move the object. Unless the location is on the desktop, you have to make a complete location reference, in the form of folder "HFSA2gig:1wordfiles" or (folder "1wordfiles" of disk "HFSA2gig").

replacing boolean

If the replacing parameter is true then any items with the same name as the items you moved are replaced in the new location. In other words, if the “actions” folder already has a LogFolder folder, then the folder you moved replaces it if replacing is true. replacing is false by default.

positioned at list

You can position the item you moved in the new location by passing the move command a point object. This is a list of coordinates specifying the upper left corner of the item’s icon.

routing suppressed boolean

This command only applies to objects that are being moved to the System Folder. The Finder automatically routes certain objects that are dropped on the System Folder icon, such as the Calculator accessory (it is routed to the Apple Menu Items folder). If you set this labeled parameter to false then a file or folder that is moved to the System Folder is not automatically routed to a certain location.

open reference to object(s)

You can open one or more files or folders using the Finder’s open command. You can also have the Finder create an object and then instruct another application (the object’s or file’s creator) to open it. Open several objects at once by passing the Finder open command a list:

open {folder "today",folder "actions"}

This command opens two desktop folders, since the Finder assumes that incomplete folder references are on the desktop. If you refer to files or folders without complete file or folder paths (unless they are located on the desktop) then your code will raise an error. Since the following are hypothetically complete path references, the Finder will open each of the folders without an error:

open {folder "Macintosh HD:Logs:JuneLogs",folder "Macintosh¬  
HD:Logs:JulyLogs"}