MoreOSA Source Code

In the course of my AppleScript hacking, I've created a pretty handy C++ script object which does all the AppleScript stuff I generally want to do. It can load scripts from files or resources, compile, decompile, run and save scripts.

It's pretty darn handy, and simple to use too. Click here to download the package.

Here's the header, which is about all the documentation you get, aside from the source:

class ScriptObject
{
	protected:
		ComponentInstance		fComponent;
		OSAID					fScriptID;
		OSAID					fResultID;
		Zone*					fZone;
		FSSpec					fFile;
		AEIdleUPP				fIdleProc;
		Boolean					fPersistentProperties;
		
	public:
		ScriptObject();
		~ScriptObject();
		
		// these will be performed automatically when needed		
		void OpenComponent();
		void CloseComponent();
		ComponentInstance GetComponent();
		
		// Memory control
		void UseZone(Zone* zone);
		void UseSystemZone();
		
		// use Compile or Load to initialize a script
		Boolean Compile(FSSpec *file);
		Boolean Compile(DescType type, Handle scriptText);
		
		// save the formatted script text
		void StoreSource();
		void StoreSource(FSSpec *file);
		
		// load a compiled script into memory
		void Load(FSSpec *file);
		void Load(AliasHandle alias);
		void Load(Handle scriptData);
		Boolean ScriptLoaded();
		
		// set a number of optional callbacks
		// idleProc should always be used or events will be lost
		void SetIdleProc(AEIdleUPP idleProc);
		// send and active procs provide time while scripts run
		void SetSendProc(OSASendUPP sendProc, long refcon);
		void SetActiveProc(OSAActiveUPP activeProc, long refcon);
		// these provide additional less used hooks
		void SetResumeProc(AEEventHandlerUPP resumeProc, long refcon);
		void SetCreateProc(OSACreateAppleEventUPP createProc, long refcon);
		
		// control whether Run methods call Store automatically
		Boolean GetPersistentProperties();
		void SetPersistentProperties(Boolean persist);
		
		// run a script by executing the run handler
		void Run();
		void Run(FSSpec *file);
		void Run(Handle scriptData);
		
		// execute an arbitrary handler
		void GetHandlerNames(AEDescList* handlers);
		Boolean HasHandler(char *handlerName);
		void CallSubroutine(char *handlerName, AEDescList *params);
		
		// send an event to the script
		void DoEvent(AppleEvent *event);
		void DoEvent(AppleEvent *event, AppleEvent *reply);
		
		// access info about the script
		Boolean IsModified();
		void GetSource(AEDesc *text);
		void GetSource(DescType desiredType, AEDesc *text);
		void ReturnResults(AEDesc *result);
		void ReturnResults(DescType desiredType, AEDesc *result);
		void ReturnResultText(AEDesc *result);
		void GetErrorMessage(DescType desiredType, AEDesc *result);
		long GetErrorNumber();
		void GetErrorRange(AEDesc *result);
		
		// save the original
		void Store();
		void Store(FSSpec *file);
		Handle Store(Handle oldScript);
		// save the original only if it changed
		void StoreIfChanged();
		void StoreIfChanged(FSSpec *file);
		Handle StoreIfChanged(Handle oldScript);
};
I don't think the project file is even in a recent version of CodeWarrior, but if you can't update/recreate it, you shouldn't be trying to hurt yourself with this.
Send your comments to me,
jonpugh@frostbitefalls.com
Jon Pugh

Return to my home page.


Created on Tue, Jul 20, 1999 and last modified on Tue, Jul 20, 1999.