To do this test, fire up Script Editor and open up a fresh “Untitled” script (do not save it). FWIW, I am running OS 10.3.
Now, try this code:
on clean(x)
return x
end clean
set topPath to clean(path of document 1 of application "Script Editor")
When I do this, I receive the error “The variable x is not defined.” Huh? Now, granted, my clean function is rather useless, but I had a much more complicated erring program which I stripped down in order to get a simple version of the error for you folks.
What’s going on, it seems, is that there is no path of doc 1. If, for example, you remove the “clean” funciton call you run the program and nothing is returned. So perhaps I am passing this nothing thing to my clean function and that is screwing with it? But this error message to me seems very incorrect. Thoughts?
You’re right, there is no path. The point is that this program should yield an error, and it does, but IMO it gives the wrong one. It should say “No Path”, or maybe something else. What it should not do is say “Undefined variable x”. I submit that this is a bug in Applescript. Do people disagree?
I see what you are saying. If, in Script Editor, I run the following in an unsaved document, it should throw an error but it doesn’t. I agree that it should.
Indeed, I tried your change and I get a “missing value” return value. That seems like correct behavior to me. So I think AppleScript is just messed up if you don’t do this properties trick of yours.
Is getting the properties and then requesting path a more preferred method? I mean, don’t you think it’s weird that your change makes it work, and mine yields and incorrect error?