TIP: Using OS 9 osaxen with OS X

This may be mentioned somewhere, but thought I’d throw it out for all who need it.

I’ve managed to build a workaround to call os 9 osax commands from an OS X script. There’s one or 2 osax for os 9 we use. We are unsure if they are going to be carbonized or not, but rather than sit with os 9, we are plunging ahead with the switch to OS X. Anyway…

Here’s the quick info: instead of having a script from OS X call an osax command directly, we use an OS X script to call a Classic Applet that calls the OS 9 osax command.

Now the in-depth stuff: We use a script addition called FindFile to search for files of a certain name. First I use Script Editor for 9 to make a script like this:

on findThis(lookHere, nameContents)
set tempFind to FindFile in_folder lookHere name_contains nameContents
return tempFind
end findThis

I save it as a Classic Applet. I also check ‘Never show startup screen’ and ‘Stay Open’.

Then in my OS X script, I can do this:

set findapp to “MyMac:Wherever:findApp”
tell application findapp
set temp to findThis(alias “MyMac:Documents:”, “Report”)
end tell

If all goes correctly, the os x script will launch, run the classic applet which in turn runs the commands from the os 9 osax. Finally, it will return the files found. It has worked for us pretty well.

Yes, I know you will need to have Classic installed on your Mac. And I know this isn’t the most effecient way to do this. The most effecient would be to learn C or Obj-C and write my own OS X osax, but since I don’t think will be happening very soon, this will have to do. =D

Please give me some feedback if this works for you or not. Or ways this can be improved.


I don’t think that you can use Obj-C to write an OSAX, but yu can use C and C++

That’s a good trick, although I may have seen it before.

One other suggestion: you can probably replace the functionality of this OSAX with a call to a command-line utility called ‘find’.

Here’s an alternate handler for ‘findThis()’


on findThis(searchIn, searchName)
 do shell script "find " & (quoted form of POSIX path of searchIn) & " -name '*" & searchName & "*' -print"
end findThis

This version returns a return-delimited list of the Posix paths of the found files, but the extra code to turn those back into files is possible.

Here’s a better handler, that returns a list of aliases:


on findInFolder(searchFolder, searchName)
	-- version 1.0, Daniel A. Shockley, http://www.danshockley.com
	if (searchFolder as string) ends with ":" then
		-- don't want double slashes in find's results, so leave off trailing slash
		set searchFolderPosix to quoted form of (text 1 through -2 of (POSIX path of searchFolder))
		set searchFolderPosix to quoted form of POSIX path of searchFolder
	end if
	set foundPosixText to do shell script "find " & searchFolderPosix & " -name '*" & searchName & "*' -print"
	if length of foundPosixText is greater than 0 then
		set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
		set foundPosixList to text items of foundPosixText
		set AppleScript's text item delimiters to od
		set foundList to {}
		repeat with onePosix in foundPosixList
			copy alias (POSIX file onePosix) to end of foundList
		end repeat
		set foundList to {}
	end if
	return foundList
end findInFolder

And, of course, you could include some test that checks whether the script is running in OS 9, and then uses your OSAX.

I tried this with some on os9 extension including jons commands and was getting weird things happen whilst running my scripts including random crashes, double finder bar and a “finder.out” window appearing.

This all stopped when I removed the offending classic additions.