Sample code to create and use a special structure in AppleScript mostly unknown as “constructor”…

  • Some of the features defined in the “constructor” maybe available only to OS X or special email clients (?), but this is simple source-code and can be adaptated :wink:

OS version: Any


This is sample code to create and use a "constructor".
A constructor is, basically, a handler which returns
an object when invoked, which owns its own properties
and methods (as defined in the constructor).

You don't need constructors by default, but they can be
useful for organization purposes (as far as I understand'em),
or under certain special circumstances.


--> input name and email address to create three new "folks"
set Joe to makeFolk("Joe Morton", "")
set Jerry to makeFolk("Jerry Bloom", "")
set Cassy to makeFolk("Cassy Black", "")

--> test the various methods available for "folks"
tell Jerry to newEmail()
tell Cassy to makeClipping()
tell Joe to composeTestEmail()

to makeFolk(x, y) --> the "constructor"
	script blankFolk
		property |name| : x
		property email : y
		to formatData()
			|name| & " <" & email & ">"
		end formatData
		to composeTestEmail()
			"Subject: test" & return & ¬
				"To: " & formatData() & return & ¬
				"From: [email][/email]
MIME-version: 1.0
Content-type: text/plain; charset=x-mac-roman
Content-transfer-encoding: quoted-printable

This is a test!!!"
		end composeTestEmail
		to newEmail()
			open location "mailto:" & formatData()
		end newEmail
		to makeClipping()
			tell application "Finder" to ¬
				make new internet location file at desktop to ("mailto:" & email) with properties {name:|name|}
		end makeClipping
	end script
end makeFolk

property |version| : 1.0
property author : "Pescados Software ·"
property |date| : date "jueves, 10 junio 2004 14:35:24"
property license : "freeware, open-source"