Don't miss Joystiq's up-to-the-minute live coverage of E3!

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.

Related Headlines

Reader Comments (Page 1 of 1)

TUAW Features

iphone app store tuaw tests
Mac 101 ask-tuaw
Mac News
WWDC (251)
.Mac (64)
Accessories (641)
Airport (75)
Analysis / Opinion (1365)
Apple (1667)
Apple Corporate (565)
Apple Financial (193)
Apple History (48)
Apple Professional (54)
Apple TV (163)
Audio (447)
Bad Apple (120)
Beta Beat (152)
Blogging (86)
Bluetooth (17)
Bugs/Recalls (56)
Cult of Mac (873)
Deals (219)
Desktops (115)
Developer (263)
Education (100)
eMac (10)
Enterprise (140)
Features (405)
Freeware (386)
Gaming (377)
Graphic Design (33)
Hardware (1287)
Holidays (37)
Humor (579)
iBook (65)
iLife (237)
iMac (184)
Internet (334)
Internet Tools (1325)
iTS (977)
iTunes (814)
iWork (22)
Leopard (370)
Mac mini (112)
Mac Pro (53)
MacBook (202)
MacBook Air (79)
Macbook Pro (220)
MobileMe (38)
Multimedia (445)
Odds and ends (1451)
Open Source (280)
OS (919)
Peripherals (210)
Podcasting (182)
Podcasts (91)
Portables (197)
PowerBook (135)
PowerMac G5 (50)
Retail (598)
Retro Mac (48)
Rig of the Week (42)
Rumors (633)
Software (4356)
Software Update (419)
Steve Jobs (252)
Stocking Stuffers (50)
Surveys and Polls (97)
Switchers (113)
The Woz (34)
TUAW Business (243)
Universal Binary (281)
UNIX / BSD (61)
Video (905)
Weekend Review (84)
WIN Business (47)
Wireless (85)
Xserve (39)
iPhone/iPod News
iPhone (1641)
iPod Family (2071)
App Store (93)
SDK (22)
Mac Events
One More Thing (27)
Liveblog (2)
Other Events (226)
Macworld (489)
Mac Learning
AppleScript (3)
Ask TUAW (103)
Blogs (85)
Books (26)
Books and Blogs (62)
Cool tools (446)
Hacks (466)
How-tos (487)
Interviews (44)
Mods (188)
Productivity (590)
Reviews (112)
Security (156)
Terminal Tips (59)
Tips and tricks (568)
Troubleshooting (168)
TUAW Features
iPhone 101 (34)
TUAW Labs (4)
Blast From the Past (17)
TUAW Tips (144)
Flickr Find (36)
Found Footage (86)
Mac 101 (96)
TUAW Interview (31)
Widget Watch (198)
The Daily Best (1)
TUAW Faceoff (5)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

The Unofficial Apple Weblog (TUAW) bloggers (30 days)

#BloggerPostsCmts
1Cory Bohon804
2Robert Palmer5946
3Dave Caolo560
4Steven Sande4820
5Mat Lu3811
6Scott McNulty370
7Erica Sadun342
8Mike Schramm221
9Brett Terpstra171
10Giles Turnbull150
11Christina Warren1324
12Michael Rose1219
13Chris Ullrich30
14Joshua Ellis23
15Kent Pribbernow10
16Jason Clarke10

Featured Galleries

Macworld 2008 Keynote
Macworld 2008 Build-up
Apple Vanity Plates
DiscPainter
Crash Bandicoot Nitro Kart 3D
Macworld Expo 2007 show floor
Apple Texas Hold 'Em
The Macworld Faithful in Line
iPhone First Look

 

    Most Commented On (7 days)

    Recent Comments

    More Apple Analysis

    More from AOL Money and Finance

    Other Weblogs Inc. Network blogs you might be interested in: