Finder Strings
Volume Number: 9
Issue Number: 4
Column Tag: Fun Hacks
Rändóm fiNdEr sgnirtS 
A cute extension to help you with April Fools Day
By By Mike Scanlin, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Recently at a friend’s house I saw a clock that ticks backwards. The whole thing
looks like a normal clock would when viewed in a mirror. I thought to myself “Not
very useful, is it? Kind of difficult to figure out what time it is. What if everything
was backwards: newspapers, controls on my car, file names in the Finder...
Hey! Cool idea for an April Fool’s INIT.” And, so, here we are.
RandomFinderStrings is an INIT (Extension) that causes one of several effects to
happen to each string drawn by the Finder: (1) the case of the letters is forced to be
upper, lower, reversed or random, (2) the letters in the string are rearranged
back-to-front, (3) all vowels get an accent mark or (4) all vowels are removed. The
effect that happens to each string is random. The framework of the code has been set up
to make it easy to add your own effects if you can think of a cool way to tweak a Str255
(maybe you could do a conversion to Pig Latin or something) or, you can just use the
code as it appears here. You can have some fun if you give this INIT an unsuspecting
name like “Easy Access” and put it on a [former?] friend’s Mac.
HOW DOES IT WORK?
The first part of the INIT code creates space for the patch and effects code in the
system heap (about 800 bytes) and moves a copy of the code there. Then it installs a
head patch on DrawString. The patched DrawString will first check if CurApName ==
“\pFinder” and that the Option key is not down. If both conditions are true then it will
randomly change a copy of the string before calling the real DrawString to draw the
string. Note that comment about the Option key. If you really need to see the true
strings once this INIT is installed, and you can’t afford to remove it and reboot, you can
hold down the Option key and cause the screen to refresh (with a screen
saver)-everything will redraw normally (but if you let go of the option key then
things begin to get drawn tweaked again).
WHAT DOES IT LOOK LIKE?
Here are some screen shots that show some of the effects this INIT is capable of.
Figure 1 shows the System Folder when ACCENTED_VOWELS is on, figure 2 shows the
About This Macintosh box when BACKWARDS_LETTERS is on and, figure 3 shows the
File menu when DO_CASE_CHANGES is on (the NO_VOWELS option isn’t shown here).
You can mix and match these effects until you reach the level of annoyance you desire
but you will have to recompile each time you change which effects are on/off. You turn
them off by setting their #defined values to 0 and you turn them on by setting their
#defined values to 1. If ALWAYS_TWEAK_STRING is off (i.e. zero) then not every
string drawn by the Finder will be modified (because of the -1 case in the main switch
statement).
Figure 1
Figure 2
Figure 3
Except for maybe the trap patching, this code is pretty easy to understand. The
actual effects that tweak the copy of the string are rather simple. One thing to note
might be the politically correct way to check if the Option key is down at a time when
we don’t have an EventRecord: We make a dummy event record and call OSEventAvail
with a mask of zero. This is a much better method than using GetKeys.
Because this is an INIT, the Think C Project Type should be “Code Resource” and
the File Type should be “INIT”. You can use whatever you want for the Creator and ID
(I used “Twen” with an ID of 55). Have fun.
/*************************************************
* RandomFinderStrings.c
*
* This INIT installs a patch on DrawString that will tweak
* strings drawn by the Finder. If CurApName != “/pFinder”
* or if the option key is down then a normal DrawString
* takes place. If we are in the Finder then a modified
* version of the string is drawn: the upper/lower case of
* the letters might be changed, the string might be flipped
* backwards, all the vowels might get accent marks, etc.
*
* You can add to the list of effects by adding an item to
* the Effects enum and the main switch statement in
* MyDrawString. If your effects need globals, put them in
* the PatchGlobals struct and initialize them in main.
*
* In Think C, set the Project Type to Code Resource, the
* File Type to INIT, the Creator to anything, the Type to
* INIT, the ID to something like 55 (55 will work but it
* doesn’t have to be 55), turn Custom Header ON and Attrs
* to 20 (purgeable) and Multi Segment OFF.
*
* Mike Scanlin. 24 Jan 1993.
***********************************************
* defines
************************************************/
#define _DrawString 0xA884
enum Effects {
UpperCase = 0,
LowerCase,
ReverseCase,
RandomCase,
BackwardsLetters,
AccentedVowels,
NoVowels,
PigLatin,
NumEffects /* must be last */
};
/* Turn these all on for maximum randomness */
#define DO_CASE_CHANGES 1
#define BACKWARDS_LETTERS 1
#define ACCENTED_VOWELS 1
#define NO_VOWELS 1
#define PIG_LATIN 0
#define ALWAYS_TWEAK_STRING 1
#if ALWAYS_TWEAK_STRING && !(DO_CASE_CHANGES ||
BACKWARDS_LETTERS || ACCENTED_VOWELS || NO_VOWELS)
not!
/* Generate a compile time error if you set up an
* impossible situation. You need to have at least one
* effect enabled if ALWAYS_TWEAK_STRING is enabled. */
#endif
/*************************************************
* typedefs
************************************************/
typedef pascal void (*DSProcPtr)(Str255 *theStringPtr);
typedef struct PatchGlobals {
DSProcPtr pgOldDS;
} PatchGlobals, *PatchGlobalsPtr;
/*************************************************
* prototypes
************************************************/
void main(void);
void StartPatchCode(void);
pascal void MyDrawString(Str255 *theStringPtr);
short abs(short n);
void EndPatchCode(void);
/******************** main ***********************
* Gets some memory in the system heap and installs the
* DrawString patch (as well as allocating and initializing
* the patch globals). This is the only routine that gets