Automated Bug Generation
AppleScript is the language for beginners. At least that’s what Apple was telling us back in those heady System 7 days when it was introduced. But every time I attempt to use it, I struggle.
Let me show you what I mean. Open up the Script Editor and type the following:
POSIX file "foo"
In AppleScript terms, this is creating a reference to an as-yet-nonexistent file, specified using a POSIX path. More specifically, it’s a special kind of reference called a “fileURL” (not to be confused with a “file:/” URL). If you believe Apple Tech Note 2022, fileURLs are to be preferred over the old skool (HFS) file specification, originally used in System 7 and possibly earlier. If this doesn’t mean anything to you, don’t worry about it.
The point is this. Look what happens when you compile this script.
Amazing. This must be the only computer language in existence where the act of compiling actually changes your source code!
In this case the change is relatively benign. The code still runs and gives the same result. However it’s pretty easy to find breakage. Let’s try the following:
class of POSIX file "foo"
Here I’m attempting to verify my hypothesis about the type of file reference created. Again the code is changed upon compilation, but it does produce the desired result when run:
Now here’s the truly amazing thing. Let’s try making a trivial change to the source — like adding a space and then removing it — then recompile and rerun:
This is just incredible. Not only does the compiler change your source code, it actually breaks it so that it no longer runs!
I must say this really is a time-saver. Thanks to AppleScript I no longer need to spend hours introducing bugs into my code; now the compiler can do it for me!
2 Comments