>
Apple-AppleScript-Script-Editor-Logo

Basic AppleScript Dialog:

display dialog "Your text here" with icon stop buttons {"OK"} default button {"OK"} giving up after 5

'giving up after 5' will automatically close the script after the indicated interval of time has elapsed.

HTML Anchor Code

Here is a sample of how to write code to link one part of your blog page to another:

<a name = "By Email">[optional text]</a> --place this where you want the link to go <a href = "#By Email">By Email</a> --this is the actual link

more HTML

HTML Code to Link to Other Web Pages

Here is a sample of code to link to another page. this is similar to the anchor code, except that the destination code is the url of the destination site:

<a href= "www.webSite.
com"> Website Name</a>

--just replace "www.webSite.
com"
with the actual url destination site and replace 'Website Name' with the prompt that the user will see.

My Links

Apple-IIc-Apple-Screen

AppleScript Note:

It might be interesting to those of you who are AppleScript enthusiasts that the HyperCard (HyperTalk) project was the prototype back in the '80's of what became the system-wide Applescript language (akin to JavaScript) that is in use today.
Apple-Mac-512-Screen
3d-iMac-Large

Trapping for List Dialog Errors

With 'List Dialog' type dialogs, since errors cannot be intercepted in an 'on error' handler, there is no 'normal' way to trap for 'Cancel' which, of course, would result in some sort of undesirable error dialog such as 'User cancelled. Error number -128'. Here is an example of one simple way I have found to trap for this type of error: set x to (choose from list {"Joe","Amy",
"Bill"} with prompt "Choose a record:")
if x is false then
else
set targetItem to (x as text)
show every record whose cell "Name" contains x
end if
When the user clicks on 'Cancel', the variable x is assigned the boolean value false. So all you have to do is set up a conditional to deal with that and to perform the usual statements otherwise.

Learning AppleScript

AppleScript-123-Book

Create Multiple Folders with Terminal

If you are more of a techy kind of person and are comfortable with using Terminal, here is a script you can use to easily create multiple folders:

First, for a single folder, type in: mkdir "Folder 1" --or whatever you want to name your folder, this creates a new directory, which, in effect is a new folder. To place multiple items in the 'Documents' folder: cd/Users/Administrator/Documents mkdir "Folder 1" "Folder 2" "Folder 3" To quickly create multiple folders, create a text file with the desired folder names (as many as you want) and name it something like 'folderList.txt'. Next type this in Terminal: cat folderList.txt |xargs mkdir Or you could create folders with the same prefix by entering: mkdir "Invoices " {"Corporate", "Individual", "Pro-Bono"}

Digg! Digg This!!

Mac LC III (1994), the first Mac that I ever owned, the CD-Rom and Zip drive were added much later.

Mac LC III (1994), the first Mac that I ever owned, the CD-Rom and Zip drive were added much later.

Basic HTML

Here is an example of a very simple HTML document:

<html>
<head>
<title>Basic HTML Document</title>
</head>
<body>
Your text goes here
</body>
</html>

more HTML

HyperCard Users

If you love HyperCard, check out these HyperTalk scripts that are easily adaptable to general needs:

Apple-HyperCard-2.3.5-Install-CD-1998

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.

Apple-HyperCard-HyperTalk-Topical-GraphicHere 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:


If you like Myst, check out the Making of Myst videos

Add to Technorati Favorites

Previous and Next Buttons

Toggle the Hilite and Set Button Sound

Apple-HyperCard-HyperTalk-Spiral-GraphThis 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

Stumbleupon

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

Apple HyperCard and AppleScript Small1This 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
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
–otherwise the error script below will be executed
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.

Add to Technorati Favorites


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
if whichKey = 6 then
send fldConvert to bg btn "convertTextCode"
–A user defined function sent to a button named “convertTextCode”
– CTRL F
else if whichKey = 24 then
clearTheMedia images
clearTheMedia movies
–User defined functions
– 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.

Add this post to Technorati Favorites

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:

Stumbleupon

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:

Favorite this site:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogosphere News
  • Live
  • StumbleUpon
  • Technorati
  • TwitThis
  • Yahoo! Buzz
  • MySpace
  • YahooMyWeb
  • HackerNews
  • RSS
  • Twitter
  • E-mail this story to a friend!
  • Internetmedia
  • Webnews.de
  • Yahoo! Bookmarks
Apple-ID-Badge

Apple-Computer-Sticker-Old
Create Multiple Folders with Terminal

If you are more of a techy kind of person and are comfortable with using Terminal, here is a script you can use to easily create multiple folders:

First, for a single folder, type in: mkdir "Folder 1" --or whatever you want to name your folder, this creates a new directory, which, in effect is a new folder. To place multiple items in the 'Documents' folder: cd/Users/Administrator/Documents mkdir "Folder 1" "Folder 2" "Folder 3" To quickly create multiple folders, create a text file with the desired folder names (as many as you want) and name it something like 'folderList.txt'. Next type this in Terminal: cat folderList.txt |xargs mkdir Or you could create folders with the same prefix by entering: mkdir "Invoices " {"Corporate", "Individual", "Pro-Bono"}

Add http://www.scriptsforapple.com to Technorati Favorites

Apple-iMac-Rainbow

Digg! Digg This!!

An AppleScript to Verify a Date

Run this in the Script Editor:

set dateRecord to (current date)
set defaultDate to (date string of dateRecord)
try
set apptDate to text returned of (display dialog "Enter appointment date:" default answer defaultDate buttons {"Set"} default button {"Set"})
set datetext to apptDate as text
date apptDate --if an invalid date is entered, the next dialog is aborted and it triggers the error alert below.
display dialog datetext & " is a valid date." with icon note buttons {"OK"} default button {"OK"}
on error
set alertText to "An error has occurred!"
set messageText to quote & datetext & quote & " is an invalid date."
display alert alertText message messageText as warning buttons {"OK"} default button "OK" giving up after 15
return
end try

Airport-Extreme-Hardware