If you love HyperCard, check out these HyperTalk scripts that are easily adaptable to general needs:
For all of you who, like me, saw the writing on the wall about HyperCard and HyperTalk when Apple announced that they were not going to support HyperCard in OSX (even though it was the prototype for AppleScript), but decided to continue using HyperCard anyway, this page is for you. Although I, of course, am still an evangelist for Apple and their (our) mission, this is very disappointing, to say the least. With that said, let’s have some fun.
Here I will present a variety of scripts, HyperTalk and AppleScripts that can be used with HyperCard, with annotation (where applicable) on how you can alter them to your specific needs. I was basically ’self-taught’ on HyperTalk since the unveiling of HyperCard in 1987 (I think it was), so I am fairly proficient.
Most of the scripts presented here are based on a database program that I developed as an ongoing project over a number of years to keep track of my business contacts.
HyperCard was the Shell App for Myst:
Previous and Next Buttons
Toggle the Hilite and Set Button Sound
This would be placed in the button script for a button named “Previous”:
on mouseDown
if the shiftKey <> down then
play "Sosumi"
–under normal conditions, the sound would be played
else
ask "Enter a sound name for this button, or 'mute' if no sound is desired"
if it is not empty and the result is not "Cancel" then
put it into theSound
put the script of me into fld "editBtnSnd"
–Need this field for necessary text manipulations
–Next lines replace line 3 of script (above play “Sosumi”) with the sound name chosen
if theSound = "mute" then
put "--play " & quote & theSound & quote into line 3 of fld "editBtnSnd"
else
put "play " & quote & theSound & quote into line 3 of fld "editBtnSnd"
end if
set the script of me to fld "editBtnSnd"
–A handler, which sets the sound played when this button is clicked to whatever system sound you choose.
end if
end mouseDown
on mouseUp
set cursor to 4
--set cursor to the 'wristwatch' cursor
go prev
end mouseUp
on mouseWithin
if not the hilite of me then set the hilite of me to true
–A boolean, in this case because previous and next buttons should toggle their hilite
set the hilite of bg btn "Next" to false
pass mouseWithin
end mouseWithin
on mouseLeave
set the hilite of me to false
set the hilite of bg btn "next" to false
--A boolean once again, because neither should be hilited if the mouse leaves without a click
pass mouseLeave
end mouseLeave
By switching things around (ie replacing ‘next’ with ‘previous’ we can set up the ‘next’ button)
Questions or comments? Contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.
Alpha Search Buttons
Find first instance of specified alphabetical character by name reference
This script presumes that you have a background field named “nameFld”. It takes the name of the button ‘A,B,C…etc’ and searches for the first instance where there is a match in the first char of fld “nameFld”
The mouseDown handler here is identical to the one found in the ‘Previous/Next’ script posted above. The real grit of this script is in the mouseUp handler:
on mouseDown
if the shiftKey <> down then
play "Sosumi"
else
ask "Enter a sound name for this button, or 'mute' if no sound is desired"
if it is not empty and the result is not "Cancel" then
put it into theSound
put the script of me into fld "editBtnSnd"
if theSound = "mute" then
put "--play " & quote & theSound & quote into line 3 of fld "editBtnSnd"
else
put "play " & quote & theSound & quote into line 3 of fld "editBtnSnd"
end if
set the script of me to fld "editBtnSnd"
end if
end mouseDown
on mouseUp
sort by fld "nameFld"
put the short name of me into theAlpha
push cd
set cursor to 4
lock screen
lock messages
lock recent
–previous 3 lines help speed up execution
go first–otherwise the error script below will be executed
put 1 into x
repeat until x=(number of cds of this stack)
find theAlpha in fld "nameFld"
if char 1 of fld "nameFld" = theAlpha then
put "true" into foundFlag
set the name of this cd to fld "nameFld"
exit repeat
end if
put x+1 into x
end repeat
if foundFlag <> "true" then
unlock messages
answer "No entries for '" & theAlpha & "' were found."
pop cd
exit mouseUp
end if
go cd entryLoc
end if
openCard
end mouseUp
If you have any questions or suggestions, contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.
Function Key and Command Key Scripts
It is best to place this in your background script to save space in your stack script, as it can get quite large after a while:
on functionKey whichKey
if whichKey = 1 then
start using stack "Stack Name"
–Here replace “Stack Name” with the name of the stack from which you want HyperCard to get data.
else if whichKey = 2 then
stop using stack "Stack Name"
else if whichKey = 10 then
edit script of this bg
else if whichKey = 11 then
edit script of this cd
else if whichKey = 12 then
edit script of this stack
else
pass functionKey
–To exit if none of the above F-Keys are pressed
end if
end functionKey
The numbers correspond to the Keys F1,F2,F3… respectively.
on controlKey whichKey–A user defined function sent to a button named “convertTextCode”
if whichKey = 6 then
send fldConvert to bg btn "convertTextCode"
– CTRL F
else if whichKey = 24 then –User defined functions
clearTheMedia images
clearTheMedia movies
– CTRL X
else if whichKey = 49 then
doMenu "Quit HyperCard"
– CTRL 1
end if
else
pass controlKey
end if
end controlKey
Take note here that the numbers corresponding to the alpha equivalents are easily determined: A=F1,B=F2,C=F3… etc. As You can see in the last instance, however, beyond alpha equivalents, it is not as easy to determine.
Questions or comments? Contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.
Converting Text to Upper case:
on fldConvert
set itemDelimiter to ","
–This is necessary because of the array below:
put "nameFld,addressFld,cityFld,StateFld,
zipFld,phoneFld" into theFlds
repeat with x=1 to 6
–The number of items in theFlds
repeat with y=1 to length(fld (item x of theFlds))
if fld (item x of theFlds) <> "" then
put charToNum(char y of fld (item x of theFlds)) into alpha
if alpha >=97 and alpha <=122 then
put alpha -32 into alpha
put numToChar(alpha) into char y of fld (item x of theFlds)
end if
end if
end repeat
end repeat
end fldConvert
For this, just place fldConvert where you want this to be executed
Check out these ‘Myst’ clips:
Part 1:
Part 2:
Questions or comments? Contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.
The Mactini – Smallest Mac in the World:


































Recent Comments