#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP

3D
3D Photo Gallery (Part 1)
3D Photo Gallery (Part 2)

Audio
Poor Man's MIDI
Make A Metronome
iPod Tricks (Part 1)
iPod Tricks (Part 2)
iPod Tricks (Part 3)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls and Windows
Double Click Listbox
Draggable Metal Window
Double Click Canvas
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls


General RB
Scrolling Windows
Using Mesage Dialogs
Case-Sensitive Word Finder
Introduction to Stacks
Wiggle Window
JPEG in PDF
Listbox Checkboxes
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 1)
Software Distribution (Part 2)
Software Distribution (Part 3)
Software Distribution (Part 4)
Exceptions
Tips and Tricks
Text Clippings Made Easy

Graphics
Drawing a Simple Gradient
The SpriteSurface: Space Game
Image Spinner
Cropping Graphics (Part 1)
Cropping Graphics (Part 2)
Cropping Graphics (Part 3)
Cropping Graphics (Part 4)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Mac OS X
Global Hot Key Event (Carbon Events)
Login Welcomer (Carbon Events)
Add/Remove Buttons
Resizable Sheets
Mac OS X Preferences Window
Using Sheets in REALbasic
Build a Bundle (Part 1)
Build a Bundle (Part 2)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Menus
Window Menu
Templates Menu
Listbox Menu

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 1)
Merlin Simulator (Part 2)
Merlin Simulator (Part 3)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation
Network Registration Codes

Resources
Picture Extractor (Part 1)
Picture Extractor (Part 2)

Serial
Caller ID (Part 1)
Caller ID (Part 2)
Caller ID (Part 3)

Speech
Speech Recognition

Socket Communication
Easy Peer-to-Peer File Sharing
MacPAD Version Checking
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part I)
Stock Ticker (Part 2)
AIM Mate

XML Manipulation
Simple XML Introduction

Video
Big Brother Video Capture

Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.

resexc2.gif (20k)




REALbasic for Dummies
by Erick Tejkowski

$19.99 @ Amazon





Files are in Stuffit 6.5 or earlier, or ZIP format.
Download Stuffit Expander

Tell us about a bad link.

Take Control of Your Command Line
05-04-01




The release of Mac OS X marked the introduction of the Unix command line to thousands of Mac-o-philes all over the world. Despite feeling like a step backwards in time, the command line (typically accessed using the Terminal application included with Mac OS X) affords Mac junkies all sorts of tricks and hacks for customizing the Mac OS.

REALbasic 3 introduces a new feature, called the Shell Class , which gives you the ability to use command line functions from within your own REALbasic project. This new feature makes it a cinch to give your OS X tweaks an interface as well as saving you from having to look up the hack each time. It also helps out those folks who are terrified of the command line (believe me, they're out there). Now, they can take part in the Mac OS X fun too.

Background

One of the more popular Mac OS X hacks around involves changing the genie effect of the dock. The hack involves launching the Terminal application and entering one of the following commands:

  • defaults write com.apple.Dock mineffect genie
  • defaults write com.apple.Dock mineffect suck
  • defaults write com.apple.Dock mineffect scale

Once you've entered a command, you must force quit the dock to make the changes take effect. To do so from the command line, you have to:

  1. Look through the various processes
  2. Find the PID of the Dock.app
  3. And, finally, kill the process using the PID.

Wheeww! As you can see, it takes quite a bit of work to accomplish this simple hack via the command line and it is hardly elegant as far as interfaces go. Luckily, REALbasic changes all of that.

Create the interface

To illustrate, begin by launching a copy of REALbasic 3. By default, REALbasic starts you off with an empty project, as shown here:

New Project (7k)

Double click Window1 in the Project Window to open the window. Then, from the toolbar, drag two PushButtons and three RadioButtons onto your Window1 interface. You can lay out the interface out anyway you desire, but it might look something like this:

Interface (10k)

The RadioButtons will permit a user to choose a genie effect, while the PushButtons will be used to change the genie effect and to restart the dock.

For the purposes of this demonstration, the PushButtons and RadioButtons will be named and labeled according to this table:

Control Name Caption Property
RadioButton1 genie
RadioButton2 Suck
RadioButton3 Scale
PushButton1 Set genie Behavior
PushButton2 Quit Dock.app

Add the code

Now, you have an interface, but it doesn't do anything yet. To add functionality, double-click PushButton1 to open the Code Editor. Add the following code to its Action Event.

// Create two variables to store the command and the Shell Object.
Dim Command as string
Dim Terminal As Shell

// Which genie behavior has the user chosen?
// i.e. Create a command depending on which RadioButton is currently selected.
If RadioButton1.Value then
    Command = "defaults write com.apple.Dock mineffect genie"
ElseIf RadioButton2.Value then
    Command = "defaults write com.apple.Dock mineffect suck"
ElseIf RadioButton3.Value then
    Command = "defaults write com.apple.Dock mineffect scale"
End If

// Create the Shell object
Terminal = New Shell

// Now, execute the command
Terminal.Execute Command
If Terminal.ErrorCode=0 then
    // No errors; everything worked without a hitch.
    MsgBox "genie behavior changed"
Else
    // Ooops, an error occurred! Display the error.
    MsgBox "Error Code: " + Str(Terminal.ErrorCode)
End If

This code looks at which RadioButton is currently selected and builds a command accordingly. The commands should look familiar from the Terminal example earlier. Next, it's time to execute the command. To do so, you must first create a Shell Object. Once you have, it's a trivial matter to send the command to the Shell Object using the Execute method. If the command executed properly without errors, then ErrorCode will equal "0" (zero) and we display a message to the user. If something other than zero is returned, then something went wrong and we display the error instead.

Of course, this code only takes care of the first step. The next step is to kill the dock, so we can see the effect of the changes we made. You could continue using the Shell Object and write some similar code that would find the PID of the Dock process and kill it. But, why bother? There's an easier way to do the same thing with REALbasic.

AppleScript to the rescue!

Yep, that's right. AppleScript can take care of this laborious function for us. Fire up the AppleScript Script Editor application and create a script like this:

05-03_quitdock.jpg (18k)

Once you have entered the necessary code, save the AppleScript as a Compiled Script making sure not to include any spaces in the name of the file. For this example, I chose the name QuitTheDock.

After you save the script, you can quit the Script Editor and return to REALbasic. Add the script you just made to your REALbasic project by dragging it into the Project Window from the Finder or by choosing File->Import. Finally, double-click PushButton2 to open the Code Editor. To the Action Event of PushButton2 add this one line of code:

QuitTheDock

Test and Build the Project

Believe it or not, that's all there is to it! To test your handiwork, choose Debug->Run. If everything works as it should, you should be able to change the genie behavior of the dock at will.

Once you have decided that you have created the project correctly, build the final application in REALbasic by choosing File->Build Application. Now, you won't ever have to type those commands in by hand again and the GUI gods will look down on you favorably.

Where to go from here

If you don't like typing or had any troubles recreating this project, you can download

If you have no interest in programming, you can also download

Keep in mind that this same approach can be applied to all sorts of Mac interface hacks. To give you some ideas, be sure to look at these links:






Please support ResExcellence by Visiting our Sponsors. One click makes a difference.


Download REALbasic and create your own software!

#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP