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."

You've just created an AppleScript that combines more than one command. I'll expand upon this in future posts.
Share
Now that you've mastered the tell command, it's time to introduce some of the other AppleScript commands that you may encounter.Location...
Add a Comment
Great tutorials for a beginner! Had my mac for nearly 2 years but never opened applescript until now or even known what it does for that matter. I like what you're doing here with starting at the basics. Thanks
December 30 2007 at 11:55 AM Report abuse Permalink rate up rate down ReplyWhere can I find a list of all the available voices for the 'say' command?
December 29 2007 at 10:18 PM Report abuse Permalink rate up rate down ReplyOpen System preferences and click on Speech. Somewhere in there is a popup box with a list of voices.
February 13 2008 at 10:16 PM Report abuse Permalink rate up rate down ReplyThis is all fine and well, but I still don't get it. I can click on a bookmark in my browser and get to this site faster than opening AS and typing in tell application "Finder" to open location "http://www.tuaw.com". What use is it? Can I save this script somewhere and run it with one click at a later date without opening AS and running it? Am I missing something about AS? Give me something useful to do with it or something that saves time. Seems like a lot of watsed time to create & run a script for something I can do with a few mouse clicks a lot faster.
December 29 2007 at 7:47 PM Report abuse Permalink rate up rate down ReplyIt's all about building up your Apple Script vocabulary at a steady pace that anyone can understand. It's hard to jump right into a new programming language and make something that useful immediately.
Personally, I learned a lot from this. This lesson gave me a bit of a primer in the general syntax of the language.
Keep going Cory! These tutorials are great and very easy to understandâkeep 'em coming!
yes, you can save any script as an application, so that you just click on it and it runs the script.
for instance, i have eight email accounts online that i check between work and personal, and while some of them could be configured to work in Mail, some of them cannot be. I wrote a simple script that i cal email and i saved it as an application. when clicked, this mini-app opens all of those mail sites at once. My Safari is set to open all new windows in new tabs, so one click and I have all of my online mail accounts (yahoo, yahoo japan, gmail, hotmail, and more) ready to read.
Thanks a lot!!! I have wanted to learn Applescript for a while now, this is a great place to do so!!!
December 29 2007 at 6:08 PM Report abuse Permalink rate up rate down ReplyThe whole 'tell application "Finder" to' stuff is completely unnecessary for most of these commands, as they are provided by the Standard Additions.
You can use 'open location' without a tell block to open the URL in the default handler for that URL's protocol (http in Safari, mailto in Mail, vnc in Screen Sharing, etc).
The 'say' command will work the same whether enclosed in a tell block or not.
Putting 'display dialog' in a tell block will cause the dialog to be layered as if it belonged to the target app, so it can sometimes be useful. If you're running your script from Script Editor and the Finder has become frontmost in the course of running the script, using 'display dialog' without targeting Finder will cause the dialog to "belong" to Script Editor, making its icon bounce and requiring you to switch back to it to dismiss the dialog and continue the script.
Restart, sleep, and shut down actually belong to the Finder, so the tell block is actually required there. However, if you're distributing your script to others, it might be better to use the System Events app instead -- it also implements those commands, and it is always present even for users who might have disabled the Finder.
BTW, the 'say' and 'display dialog' commands are part of Standard Additions--not the Finder. So, one can drop tell "Finder" portion to simplify this in the editor:
say "Hello, my name is Macintosh." using "Bruce"
display dialog "Hello, there."
whats the difference between the normal "display dialog" command and telling finder to do it?
December 29 2007 at 1:49 PM Report abuse Permalink rate up rate down ReplyGreat stuff this. I've known about the Dictionary in Script Editor for quite some time what puzzles me though is if there's any resource for all the other "system wide" commands? Things like delay or shut down etc. I once heard that the last official documentation on AppleScript is from when Mac OS 8 was current. Which would suggest there are no great resources out there.
December 29 2007 at 12:51 PM Report abuse Permalink rate up rate down ReplyThanks for this series. AppleScript was one of the things I had been hoping to learn when I switched to Mac, and these tutorials are a great help. Keep them coming!
December 29 2007 at 11:24 AM Report abuse Permalink rate up rate down Replyme too, this was very fun, i always wanted to be able to write up apple scripts, and i currently only have one that i use, even though i didn't make it. make the next lesson soon, because i can't wait to learn...i wish school was this fun.
December 29 2007 at 11:17 AM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



18 Comments