- 0 Comments
- 0 Recommendations
Amazing AppleScript! Page 3 of 4
Learn Apple's Simple Scripting Language, and Your Mac Will Be at Your Command
Desktop Setup Script
Using all the properties and verbs we’ve covered so far, you now have the tools to create a script you can use to quickly restore a cluttered desktop to a default window configuration.
Tell Block To set the desktop window display to the desired format, this script will perform a series of eight commands. But instead of writing a group of individual
tell
statements, we’ll shorten the time it takes to write our script by enclosing the commands in a
tell
block—used to target multiple actions at a scriptable object (in this case, the Finder application) and to make scripts easier to read and write.
A
tell
block begins with the verb
tell
followed by a reference to a target object. The various actions to be performed are then listed, each on its own line. The
tell
block ends with the closing statement
end tell. All actions inside the
tell
block target the object referenced in the opening statement. You’ll always want to use a
tell
block in your scripts when you’re addressing more than one action at a scriptable object.
The ScriptDelete any remaining script from the script window, and then enter, check, and run the following script:

tell application "Finder"
close every window
open home
set the current view of the front window to icon view
set the bounds of the front window to {14, 64, 512, 481}
open folder "Documents" of home
set the current view of the front window to list view
set the bounds of the front window to {523, 64, 907, 482}
select window of home
end tell
You should now see two Finder windows placed side-by-side on the desktop—one in icon view, the other in list view—with your Home directory as the active window.
Save the script as a script applet and install it in the Finder toolbar (see below). Choose Save from Script Editor’s File menu. In the dialog box that appears, navigate to the Library folder in your Home directory. Click on the New Folder button and create a new folder named Toolbar Scripts in the Library folder.

Next, enter a name and save the script as a self-running application named Setup by choosing Application from the File Format pop-up menu in the dialog box. Make sure the Startup Screen option is not checked, and then click on the Save button. The new script applet will be saved in the newly created folder in your Library folder.
Switch to the desktop and open the Toolbar Scripts folder you just created. Drag the script applet icon to the Finder window toolbar, and release the mouse. The script will now be available from within any open Finder window. Anytime you want to return your desktop to your default setup, just click on the script icon in the toolbar (and with your newfound knowledge of AppleScript, you can customize this script to your liking).
The Last Word
Now that you’ve finished your initial foray into the world of AppleScript—having learned what it is, how it works, and how to script the Finder to control the display of Finder windows—you have the background you’ll need to write more-advanced scripts.
Sal Soghoian is a noted AppleScript guru and serves as AppleScript product manager for Apple Computer.
- Recommend? 0 YES 0 NO
- 0 Comments




