Back to Mobile View

Skip to Content

TUAW Deals

AppleScript: Finder commands

Now that you've mastered the tell command, it's time to introduce some of the other AppleScript commands that you may encounter.

Location command
This command will allow you to open a specific location (either on your Mac or on a web server). This command is most often used with the Finder. For instance, if you wanted to open "www.tuaw.com," then you would type:

tell application "Finder" to open location "http://www.tuaw.com"

Remember, when dealing with an application always include quote marks around the application name. When you're typing a URL, be sure to include the prefix (HTTP:, AFP:, FTP:, etc.) and include quote marks around the URL. You can also tell a specific web browser to open the URL:

tell application "Safari" to open location "http://www.tuaw.com"

However, if you use the Finder version of the script, it will open your default browser.
Say Command
You can use the say command to make your Mac talk to you. This is one of the most simple of the AppleScript commands. For instance, if I wanted the default Mac voice to say "Hello, my name is Macintosh," then I would type:

tell application "Finder" to say "Hello, my name is Macintosh."

With this command, your Mac can say anything you type; just remember to place the text in quote marks. If you want to use a voice other than your system's default add "using" after it, and then the voice name.

tell application "Finder" to say "Hello, my name is Macintosh." using "Bruce"

or

tell application "Finder" to say "Hello, my name is Macintosh." using "Vicki"


Display Dialog
This command is especially useful for shared Macs as you can use it to alert users upon login (I will get in more detail about this next time). Using this command will produce a dialog box on your screen. For instance, if I wanted to display "Hello, there," I would type:

tell application "Finder" to display dialog "Hello, there."

A small Finder dialog box will appear with the text you've just typed.


System Events
You can also use AppleScript for system events such as: shut down, sleep, restart, etc. This is how you format these commands:

tell application "Finder" to shut down

tell application "Finder" to sleep

tell application "Finder" to restart


Building a Script
Now, let's build a script linking together the Display Dialog and Say commands.

tell application "Finder" to display dialog "Hello there, click OK and I will talk to you."

tell application "Finder" to say "Hello, my name is Macintosh; I like Apples."



Once you have it typed, click Run; Finder will display a dialog and, once you click OK, will speak the text. Notice that if you click "cancel," it will not use the say command (in other words, it stops the work flow at that point).

You've just created an AppleScript that combines more than one command. I'll expand upon this in future posts.

© 2014 AOL Inc. All Rights Reserved.