AppleScript Studio: Applications Using New Templates Won‘t Work on Earlier Versions of Mac OS X

Newly created AppleScript Studio applications built using AppleScript Studio 1.2 templates in Mac OS X 10.2 will not work on earlier versions of Mac OS X. This document describes how to correct this compatibility issue.
Symptom

Newly created AppleScript Studio applications built using AppleScript Studio 1.2 templates in Mac OS X 10.2 won't work on earlier versions of Mac OS X.


Solution

The function call ASKInitialize in main.m, is only present in the Mac OS X 10.2 version of AppleScriptKit, so AppleScript Studio applications won't work on earlier versions of Mac OS X. A new version of main.m is provided below. Use this version to replace the contents of your existing main.m file. This changed versions of main.m checks for the existence of the function, then conditionally calls the ASKInitalize function.

main.m is normally located in the Other Sources folder, from the Files view of your project in Project Builder.


Note: Previous applications built using prior versions of the AppleScript Studio templates will compile and work on computers using Mac OS X 10.1 through Mac OS X 10.2 when recompiled using the Mac OS X 10.2 development tools. However, some of the new Mac OS X 10.2 features cannot be used since an older version of main.m is used.

Location of main.m

You can find the main.m files in the following directories:

/Developer/ProjectBuilder Extras/Project Templates/Application/AppleScript Application


/Developer/ProjectBuilder Extras/Project Templates/Application/AppleScript Document-based Application


/Developer/ProjectBuilder Extras/Project Templates/Application/AppleScript Droplet

main.m will be changed in the next release of the developer tools.

main.m (new modified version)


#import <mach-o/dyld.h>

extern int NSApplicationMain(int argc, const char *argv[]);

int main(int argc, const char *argv[])
{
	if (NSIsSymbolNameDefined("_ASKInitialize"))
	{
		NSSymbol *symbol = NSLookupAndBindSymbol("_ASKInitialize");
		if (symbol)
		{
			void (*initializeASKFunc)(void) = NSAddressOfSymbol(symbol);
			if (initializeASKFunc)
			{
				initializeASKFunc();
			}
		}
	}
	
      return NSApplicationMain(argc, argv);
}


Note: This software code is considered an upgrade and its use is governed by the terms of the original license agreement.

Published Date: Feb 19, 2012