An explanation requested on "name of theObject"

Can someone please explain to me why this works:

on clicked theObject
	if name of theObject is equal to "addDefault" then
		log "moo"
	end if
end clicked

but this throws an error?

on clicked theObject
	log (name of theObject)
end clicked

(A “NSReceiversCantHandleCommandScriptError (4)” error to be exact)

I don’t get why, if the name of theObject is equal to a string value, then why can’t that string value be logged? Adding to my confusion is why you can simply log theObject and get a meaningful string out of the Log window, but that’s beside the point.

Model: PowerMac G5 dual 2.7, OS X 10.4.7
AppleScript: 1.10.7
Browser: Firefox 1.5.0.6
Operating System: Mac OS X (10.4)

You’ve found one of the kludgier aspects of AS Studio. According to what most of us have been taught, your

log (name of theObject)

should work.

In reality, most of the AS interfaces to Cocoa (which is what you’re dealing with in Studio) require you to get the information before you try to do anything with it. So if you say

set myName to name of theObject
log myName

that will work, I’d imagine.

As for why

log theObject

works who knows? Probably the Apple engineers built that support in for themselves, so they could view what was going on with an object and now it works and other stuff doesn’t.

FWIW, I don’t use log. It find it’s a pain to keep Console open while I’m working and switching back and forth. I’m a cheapskate and use say instead, then I get immediate audio feedback. If you set a variable “verbal” to true or false in your code, you can switch that debug information on and off as you work on various parts of the app. Of course, when you’re done you should remove them, though.

or - a little bit shorter:

log (get name of theObject)

should also work …

Why don’t you use ‘log’ when executing the app from Xcode (and see the results in Xcode’s Run Log Window)?

D.

Great, thanks for the information, both Kevin and Dominik. I guess that makes sense in a way, and now I have a way to work around it. Someday this ASS thing will make sense to me…

Thanks again!

PS - Dominik, thanks in particular to the one-liner tip…I’m partial to writing code as compact as possible, and for a simple “log the button that was clicked” line, that trick is great.