Apple Logo Itsamac Hosting
Mac OS Journal
EditorialsColumnsFeaturesReviewsArchives/StaffSubscribe
 
Table of Contents From the Desktop Connect Feature Column Special The CoXFiles The Gaming Landscape The Surf Report Simply Web Advanced HTML
Medicine Man The Database Guru The AppleScript Foundry Shop Talk Review - GoLive Review - Asteroids Review - BBEdit Review - Agentsheets Behind the Scenes      
   
 
Itsamac.com
Red Light Runner
Applelust.com
     
 

The AppleScript Foundry
November 2000 || Volume 01, Issue 04

 

Development Tools and Silliness

Greetings and Salutations! Well, I'm back! My apologies to those of you who tuned in here last month to find that I was off. Many thanks to Marc, our editor, for the brief respite!

This month I wanted to stop for a moment and take a look at some AppleScript stuff that I believe merits your attention. One is a great development tool, and the other is just darned silly. Next month, we'll take a look at the newly added AS capabilities of Adobe Illustrator 9.0.

SMILE For The Camera

The first thing I want to tell you about is SMILE, a replacement for Apple's Script Editor. If you have ever been frustrated using Script Editor, SMILE may be just what you are looking for. It has features that Script Editor should have had all along (in my opinion) like the ability to search and replace text, find definitions of commands, drag and drop, and many others.

Best of all, its FREE. That's right, I said, "FREE." Developed by Satimage in France, it is available in both French and English versions. It requires System 8.5 or higher and a Power Macintosh (PPC 601 or higher -- sorry 68k users!). It supports the Appearance manager and the new Navigation Services that were added in OS 9. The current version is 1.7.2 and you can find it here. It is also available via the Satimage web site, but you must click the "English" icon in the left panel to get the page translated from French. Then scroll down the right panel until you find a reference to SMILE.

Reasons to SMILE

My biggest gripe with Apple's Script Editor has always been that you could not search your scripts for text or do replaces. SMILE fixes all of that. Using SMILE, you can search for any text (commands, variables, expressions, etc.) and replace it. You can also search multiple files in a directory (say for all occurrences of the word "Finder") and optionally have SMILE open any files that find the search word/phrase.

Note, however, that you can't do replaces on multiple files. Although some text editors are able to do that, it's a fairly dangerous function in the wrong hands - you can destroy lots of files with a single mouse click! Once you have performed a multiple file search with the "Open files hit" option, it's fairly easy to do a replace on the files returned, assuming you decide that is appropriate.

Immediate Execution!

No, nobody is getting killed. What I'm talking about is the ability to test bits of code in SMILE's "Worksheet" window. Not sure how to phrase a statement? Not sure what value will be returned from a function call? Test it first in the Worksheet. Type the bit of code you are unsure of and press the Enter key -- SMILE will return the result! (The return key only goes to a new line, so you can test entire "chunks" of code.)

SMILE's Worksheet window

You can also separate your typed lines or bits of code from the output they return by opening an output window. This works for the Worksheet window or any other text window, not for the actual script window itself.

The Output window shows the results of the last two commands

Smile's Worksheet window is a plain text window. For creating a script, you must open a script window. Once you have tested the bit of code and know that it's what you want, you can transfer it to the script window using Drag and Drop.

Script windows have an extra set of tools at the bottom. The "C" will open the Comments pane, so you can add author or version information to your script, much the same as Apple's Script Editor. The right-pointing triangle is the "Run" button, and will run your script. The checkmark will compile your script, checking it for errors.

A script window - note the colored background and new tools at the bottom

The last item, the popup menu, requires some explanation. If you remember my column on Folder Action Scripts, you know about "handlers" -- pieces of AppleScript code that "handle" events. The popup menu will list any handlers that are defined in your script, and allows easy access to them -- just select one from the list and you'll hop to the section of the script where it is defined!

Look It Up In The Dictionary!

Not sure of the syntax of a command? Or want to find out if it is in the Finder's dictionary or Scripting Additions? Just highlight the command in your text or script window and select "Find definition" from the Edit menu. SMILE will check all the dictionaries and installed scripting additions it can find and pull up the item's definition. You can then check the various options for the command and if it belongs to an application, insert the appropriate "Tell" block.

The Dictionary

Another way to make sure you get the correct wording for a command is to use the "Balance" function under the "Scripts" menu. If you start a statement, like "display dialog" and aren't sure what parameters it will accept, highlight the words and use Balance. The editor will complete the statement with all the possible parameters! You can then change or delete those that you need to.

There are many other features of SMILE, but those are the major ones that beginners will find useful. More advanced users will find features like "Find Far Error," numeric conversions (Hex to Decimal, etc.), and a "Variable Watcher" window where you can track the values of variables you are working with in a text window.

SMILE features help in the form of Help Viewer files. Although some turns of phrase are awkward due to the translation from French, I was able to understand all of the material without too much problem.

I highly recommend this tool for both beginners and advanced AppleScripters. Like BBEdit, the multipurpose text editor, it takes some time to learn all of Smile's features, but you can use as many or as few of them as you are comfortable with.

Stupid Mac Tricks

Just when I thought I had seen it all, along comes a fun collection of games written in AppleScript. Called, appropriately, "Stupid AppleScript Games," the collection of 9 games includes BlackJack, Guess the Number!, War, Tic-Tac-Toe, Echo, Hangman, Matcher, Scrambler, and Rock, Paper, AppleScript.

I was a bit disappointed that BlackJack didn't allow splits (it does, see "Matt and Kynan Respond" below) or double-downs, but really enjoy playing Echo. It's like "Simon," where the computer begins a pattern of letters or numbers and you have to repeat them back. Played with the Mac's speech output, it's very entertaining.

Hangman and Scrambler (an anagram game) will let you select the text file to draw words from, which is a nice touch. And Rock, Paper, AppleScript is great for those times when you are too brain dead from writing AppleScript (or a column about it) to think any more!

The Read Me file directed me to Kynan Shook's iTools web site. The games themselves were written by Matt Garrison and Kynan. There wasn't much info about Matt on Kynan's pages but Matt wrote to me, and they admit to being high school students who have taught themselves HTML, BASIC, and (presumably) AppleScript.

Matt and Kynan Respond

BlackJack does allow splits! If the first 2 cards you are dealt have the same number, a Split button should appear and allow you to play both the hands. The only thing that we know isn't there and could/should be is insurance against the dealer showing an Ace as their first card. That may come in the future...

A tenth game is nearing completion, Pico-Fermi-Bagels (this is just like the board game MasterMind). It will probably be released before the end of October.

We've known each other for about 4 years. Both of us have written several AppleScripts to do stuff on the Macs at school, both simple and complex. In addition to AppleScript stuff, I (Matt) have made my contribution to the Newton community (yes, I'm an avid Newton user, and so is Kynan!) by making an app for the Newton that has specs for all of Apple's computers (I find this very useful when I need to look up info for a machine I'm servicing).

In regard to your comment about writing a "real" program, we have gotten an offer to write a script for a company [See the next section - Kevin]. Negotiations are still going, but it seems like it will be possible.

Play = Practice

Writing games is one of the most enjoyable ways to learn programming. I say this because that was how I learned, also. When I got my first computer (Not an Apple -- It was a Coleco ADAM that ran a rip-off of AppleSoft BASIC), I wrote a program called "Taxman" that I had seen demonstrated during a tour of a local university.

The concept of Taxman was simple -- the computer would generate a list of numbers from 1 to 40 or so (I think how high the list went was selectable by the user). The user took turns with the computer selecting numbers from the list -- for every number the user took, the computer took "taxes" in the form of all the numbers that would divide into the user's number. So if you picked 40, the computer got 8, 5, 10, 20, 4, 2, (and 1 if it was left). If this was the first turn, the user had a score of 40 and the computer had 50! This went on until there were no numbers left with factors. The "Taxman" got the leftovers, of course.

Trying to figure out the logic of the program taught me a lot about both programming and math. When I got my first Apple (a //e), I wrote a program called "Romulan Hunt" that involved finding a hidden enemy ship before it blew up yours. I've since written versions of that game for my own enjoyment on everything from an IBM PC to the VAX we had at school. I even wrote a version in HyperCard! Writing it, I "rediscovered" the Pythagorean Theorem (to triangulate the distances in Cartesian (x,y) coordinates, I had to compute the length of the hypotenuse of a right triangle).

When I got my Apple IIGS, I wrote a version of "Towers of Hanoi," a game where you move a graduated stack of coins from the first spindle to the third without ever putting a larger coin on a smaller one. I fought through the logic of that program to get it to play against itself, and in the process learned about recursive functions (a function that calls itself).

I think many beginning programmers write little amusements for themselves that they are too embarrassed to share. But I encourage you to look at what Kynan and Matt have done and then I challenge you to write your own little game. It's great preparation for when you need to write a "real" program.

More About the AppleScript Foundry

Every month in the AppleScript Foundry, I'll be sharing what I know about scripting. Since the object of this column is to get people who are new to scripting up and running, I will take a hands on approach, explaining new terms along the way. However, it is not my goal to talk down to the reader - If you want harder stuff, just write me! You can reach me at kevin@macosjournal.com or you can use the handy web feedback form.

Here is a list of places you can go to get more info on AppleScript:

Kevin's Icon Kevin Bradley - kevin@macosjournal.com
Kevin's Page Feedback Form

back Mac OS Journal forward
 
 
   
© 2000 - 2004, MacOSJournal.com. All rights reserved. No part of this publication may be reproduced in any way without prior, expressed permission from the Publisher. It is the sole property of MacOSJournal.com and its writers, who retain copyright to their own works. If you wish to link to us, please see our Privacy Statement for conditions. Apple, Macintosh, and Mac are trademarks of Apple Computer, Inc, with whom we are in no way affiliated or endorsed.
Hosting provided by itsamac.com -- Macintosh Powered Web Hosting
Serve Different