Sniffing for Intel Macs with Director MX 2004 and Buddy API
New hardware can play nice with older software, and vice-versa
Believe it or not, there are still folks out there using Director for multimedia authoring, even as Adobe pushes the Flash platform ever forward and preps AIR as the technology of choice for desktop-based applications. And while it's been more than a year of silence since the "Director is not dead" proclamation was issued by Adobe's former Director Product Manager, in the interest of keeping the fires lit, here's a tidbit for how to make Director projectors (with the help of the essential Buddy API Xtra) recognize whether they're running on an Intel or a PowerPC-based Mac.
The question is: why?
First thing's first: "why" seems to be a valid question, as in, "why would you ever need to tell the difference between Mac architectures?" A valid question indeed, especially in light of how old the latest build of Director is as of this writing. It's still a Macromedia-branded product, for Pete's sake, and it's further dated by having both "MX" and "2004" directly in the title. Heck, you can't even build Intel-native projectors with it, which means the Rosetta translation technology, miraculous as it may be, will often mean lesser performance than on PowerPC-based Macs. In light of all that, Director is still a good choice for smaller projects that require rapid development, things like stub projectors that simply serve as a launching interface to CD ROM-based content or Web links, and Rosetta provides perfectly acceptable playback for these types of low-drag applications. As for why one would need to tell the difference between PowerPC and Intel Macs, a very specific example would be to look no further than Adobe's own Reader, which often gets distributed with such CD ROM products and is provided as either a PowerPC or Intel build (not as a single Universal build for both processor types). So, instead of having the user pick which CPU they happen to have, you can have Director call out to the Buddy API Xtra to find out and launch the appropriate installer.
Next question: how?
We're led now to the rather large problem of neither Director nor Buddy API having any native way to discern between PowerPC and Intel-based Macs. As I mentioned before, I consider Buddy API to be absolutely essential for Director development, providing all manner of system-related info and extending Director in myriad useful ways. And while it can do all kinds of things, such as tell which version of Windows or Mac OS it's running on, QuickTime information, file associations, and so on, it won't tell you what kind of processor your Mac has. However, it can determine whether a specific file exists on your system, which is the key to how we're going to solve this specific problem.
So, in theory, all we need to do is look for a file that the Intel version of Mac OS X has that the PowerPC version doesn't. Or vice-versa, as the case may be. And, as it turns out, there is at least one such instance: Intel Macs use EFI (or Extensible Firmware Interface) to boot, while PowerPC Macs don't. Consequently, Intel Macs have a file called boot.efi buried in the system folder, while PowerPC Macs lack such a file. There may be other examples, but boot.efi is something of a "low-hanging fruit," so to speak, and as such is ripe for the picking. So all we need to do is have Director tell Buddy API to look for the boot.efi file where it lives, and if it finds it, we know we're dealing with an Intel Mac. If it's not there, by process of elimination, we've got a PowerPC Mac on our hands. So let's spell out a bare bones example and get to the code to make that happen.
The steps
Let's gather the parts together first. You have to have Director MX 2004, of course, which I'll already assume that you do since you're reading this piece in the first place. You'll also need Buddy API, which you can use in its unregistered form for our purposes today. The unregistered version allows access to two functions, and while I highly recommend purchasing either the seven function or unlimited function version (since you won't be able to limit yourself to only two once you really get into it), two functions are all we'll need for this example. Lastly, it would help to have a PowerPC and an Intel Mac handy, but one or the other will suffice. The code here will work fine regardless of platform, and if you are working on a Windows box and need to know how to set Buddy API up to work in a cross-platform publishing environment, may I direct you to an ancient-but-relevant tutorial I wrote many moons ago:
With the software set up and Buddy API installed, let's move over to Director and get this sucker working. Launch Director and make a new movie (Command+N on Mac/Control+N on Windows), and before we forget, it's a good idea to embed the Buddy API Xtra into the movie right away. Head to the Modify menu, select the Movie submenu, and click on Xtras. This will bring up the Movie Xtras panel. Click the Add button, which will bring up the Add Xtras panel, and select Buddy API Xtra if you're on a Mac or budapi.x32 on Windows (fig. 1). Click OK on both panels to dismiss them, and we're set.

Figure 1: Mac on top, Windows on the bottom, just so you can see things on your preferred OS.
Next, even before we write any code, let's tell Director how to publish the projector. Select File:Publish Settings, which will (unsurprisingly) bring up the Publish Settings panel, and make sure you have the Formats tab selected. Since we're only going to publish an OS X projector, make sure to uncheck all the types except for Macintosh Projector (fig. 2). Specify IntelSniffer as the name, and then click OK to dismiss the panel.

Figure 2: Again, Mac on top, Win on bottom, but don't get fooled by the field position reversal.
Now we're ready to write the code. Since we're going to produce the most basic of projectors here, we just want it to launch, call an alert box that tells you the platform, and then quit once that box is dismissed. So all we have to do is put some Lingo into the Movie Script and call it a day. The fastest way to create a Movie Script is to hit Command+Shift+U on the Mac or Control+Shift+U on Windows, and the Movie Script will appear in the Script Window. Type the following into the Script Window:
on startMovie
if baFileExists(baSysFolder("system")&"Library:CoreServices:boot.efi") = 1 then
alert("This is an Intel Mac")
else
alert("This is a PowerPC Mac")
end if
end
Line 2 is where everything happens here, so let's break that down a bit. The baFileExistsfunction is as it sounds; it checks for the existence of a file. I'm then creating the path to the file dynamically, mashing together the baSysFolder("system") function (which tells me the path to the System folder instead of having to guess what you've named your hard drive), with the remainder being the hard-coded path to the boot.efi file. The "= 1" part goes back to the baFileExists function, serving as a boolean (or true/false) statement for whether the file exists. On an Intel Mac, you'd get 1; on a PowerPC Mac, this would return a 0. So I'm checking to see if the statement equals 1, and if it does, claim that you're on an Intel Mac. Otherwise (else), you're on a PowerPC Mac.
Now, if you're on a Mac already, you can simply play the movie in the Director environment to test it out (though you're certainly welcome to publish it if you like and try it that way). If you're on Windows, you'll definitely need to publish the movie first, then move the resulting .hqx archive over to a Mac and unpackage it before you run it. When running the movie on my Mac Pro, the alert box looks like this (fig. 3):

Figure 3
On a, say, G5 Mac, you should get the PowerPC alert. You'll also get the "This is a PowerPC Mac" alert on Windows (as Windows doesn't have a boot.efi file either), but since we're not concerned about Windows for this particular exercise, we won't worry about that. You can always hide the code inside another if statement that checks for the platform first, but that's overkill for our purposes.
Anyway, that should do it. Director may be out of date, and I (still) anxiously await news on a new version (one which would be a visual IDE for AIR—hey, a dude can dream), but in the meantime, work still has to get done, so enjoy!
Got Feedback? to send an email. I'll do my best to answer. Really.
