Very Basic AppleScript

by Clay Moore on March 1, 2010

in AppleScript Mondays,Computers,How to,programming

I have been looking at AppleScript for some time now, and I thought I would give you a taste of the language and what you can do with it. You have to have a Macintosh for this. After the Break, a taste of AppleScript from a very basic level.

More than anything else the Macintosh is very “usable” computer. One aspect o this usability is the ability to tell applications that reside on your computer what to do and when to do it through the use of AppleScript. In order to do this the application must support AppleScript. In this very basic introduction we are going to script the Finder, and no other application.

Screenshot2010-02-28at5.33.37PM.png

To start using Applescript you should use the AppleScript editor which in SnowLeopard is hiding in the Utilities folder of the Applications folder. It is named AppleScript Editor. When you open the editor it will have an editing area where you will be entering your AppleScript code.

To get a feel of how the scripts work we will be running the scripts inside of the Editor. The first things to understand is how AppleScript tells applications to do things. You see the syntax of AppleScript is very English like. They did this to make it somewhat easier to do things with AppleScript. Since we are going to be telling the Finder to do something, we start out by typing tell application “Finder”. The quotes are required. Let’s tell it to do something like opening the finder window for the startup disk. The full statement is tell application “Finder” to open startup disk, just like in the screen shot below.

Screenshot2010-02-28at5.22.43PM.png

When you got that typed in and correctly just press the run button. The startup Disk for this session will open , and you will see the files and folders at that level of the disk. You can also tell the Finder to close the front most Finder window with an almost english command tell application “Finder” to close front Finder window, as in the screen shot below.

Screenshot2010-02-28at5.43.34PM.png

When you run that second script you will see a result of {} which means it did what you said. This is a very basic beginning with AppleScript. If you have been thinking of getting into scripting, then this is for you.

-EDIT-

This seems to be well received, so I will be doing an AppleScript tutorial on Mondays.  I’ll make a category of AppleScript Mondays.  I will try to present these posts in a good order to help you learn AppleScript.

[ad#ad-3]

Be Sociable, Share!

Related posts:

  1. AppleScript Mondays: Let’s Open a dictionary
  2. Applescript Monday: Make a Clear Desktop Script
  3. AppleScript Mondays: Extending the Clear Desktop Script
  4. Can the Cloud replace the Finder?
  5. Basic Databases

Leave a Comment

*

{ 2 trackbacks }

Previous post:

Next post:

<