#!/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.

Text Clippings Made Easy
05-10-01




Of all the great technologies available to Mac users, perhaps the most overlooked is that of the Clipping file. Clipping files permit you to store data in a file that can be viewed from the Finder. Furthermore, they are especially nifty, thanks to drag-and-drop.

Text clippings are handy for quick storage of text data such as:

  • Internet bookmarks
  • Email addresses
  • Software registration codes
  • Code Snippets
  • Phone Numbers
  • ResEx hacks

Of course, clippings can hold other kinds of data, but for now we will limit the discussion to text.

Creating Text Clippings

To create a text clipping, open your favorite text editor (even Simple Text will work here). Type a few letters, select the text, and drag that text to the desktop. The text becomes its own miniature file. Double click the clipping file in the Finder and it opens to reveal the text in a Finder window. While the text clipping is open, you may also copy the text to the clipboard.

Resource Information

Text clippings usually consist of two or three resources. The important one here, though, is the 'TEXT' resource. As you probably guessed, this is where the text of the clipping resides.

So, what on Earth does this have to do with REALbasic? Armed with REALbasic and your knowledge of text clippings, you can create a miniature "database".

REALbasic makes it easy to work with resources. Text clippings are already very versatile, but sometimes it is a nuisance to constantly open the clipping to view its contents. This example shows you how to keep tabs on your text clippings and make them even more useful than ever.

Build the Interface

To create the interface for this project, fire up REALbasic and open the Window1 Window Editor. From the toolbar drag the following into the window:

  • Listbox
  • EditField
  • PushButton
The Listbox will display your library of text clippings, and the EditField will show the the contents of the Clipping currently selected in the Listbox. Finally, the PushButton will give you the chance to copy text to the clipboard from the EditField. Make certain that the MultiLine property of the EditField is checked. Your interface might look something like this:

interface.jpg (17k)

Add the Code

To make the interface do something, double click Window1 to open its Code Editor. In the Open Event of the window, add this code: dim n,i as integer
dim f as folderItem

// Get the FolderItem
// for the folder that contains
// the clippings.

f = GetFolderItem("clippings")
if f <> nil then
  //how many items are in this folder?
  n = f.count
  //now loop through the items in the
  //folder and look for text clippings with MacFileType = 'clpt'
  for i=1 to n
    //if this item a file (i.e. NOT a folder)
    if f.item(i).directory=FALSE then
    //if this item is a text clipping
       if f.item(i).MacType="clpt" then
        //then add it to listbox1
        listBox1.addrow f.item(i).name
       end if
    end if
  next
end if

This code first looks for a folder named "Clippings" in the same directory as your application. If you haven't yet, create this folder now. This folder will be your storage place for text clippings. Next, the code loops through the items in the "Clippings" folder, looking for clipping files. When it encounters one, the file's name is added to the Listbox.

Next, open the Code Editor to the Change Event of the Listbox and add this code:
//This code executes when you
// select an item in Listbox1

dim f as FolderItem
dim rf as ResourceFork

// Is there anything in the listbox yet?
if me.listindex>=0 then
  // Get the file with currently selected name
  f=GetFolderItem("clippings").Child(listBox1.text)
  if f<>nil then
    rf=f.OpenResourceFork
    //get the text from 'TEXT' resource #256
    //and put it in EditField1
    EditField1.text=rf.GetResource("TEXT",256)
    rf.close
  end if
else
  //nothing in the listbox, so display nothing in the EditField
  EditField1.text=""
end if

This code will fire each time a row is selected in the Listbox. When a row is selected, the code creates a FolderItem representing the particular Clipping file. This FolderItem's resource fork is then opened and the 'TEXT' resource is retrieved (resource # 256) and displayed in the Editfield. The code concludes by closing the resource fork.

Finally, add code to the PushButton's Action Event :
Dim c as Clipboard
//Make a new clipboard object
c=New Clipboard

//copy the text from editField1
//to the clipboard
c.text=EditField1.text
c.close

This code copies the text from the EditField to the Clipboard. Of course, you can also select the text manually and copy it using the traditional Edit->Copy menu. You gain this functionality for free with the EditField.

Test and Build

The last step is to test and build the project. Test it by selecting Debug->Run. When you are sure that everything works as expteced, select File->Build Application. Once you have finished building your application, add a bunch of text clippings to your "Clippings" folder and you gain instant access to the contents of each. The project is also compatible with Mac OS X, so you can create an Aqua version as well.

If you are having troubles getting the code to work, you can

Download the code and the finished product.






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