"on awake from nib theObject" works; "on clicked theObject" doesn't

I have a 25-button GUI where nothing happens when I click the buttons. I’m assuming that I don’t have things set properly in the “NSButton Inspector”. Under “Event Handlers”, I have “Action” and “clicked” checked; and I have tried with “Nib” and “awake from nib” checked.

This is a single-button subset of my script:


set connectionName to "New Connection"
set controlByte to "0"

on clicked theObject
		
	if name of theObject = "Power" then
		set controlByte to "87"
		send_list(controlByte)
	end if
	
end clicked

on awake from nib theObject
	tell application "Serial Bridge"
		activate
	end tell
	tell application "GraphicConverter"
		activate
	end tell
end awake from nib

on send_list(controlByte)
	tell application "Serial Bridge"
		send to source connectionName byte list {255, 192, 0, controlByte, 127}
	end tell
end send_list

When I do a “Build and Go” from Xcode, the two applications start up, but I get nothing from the buttons.

All help appreciated.

-Dave

Model: Intel-CPU iMac running 10.4.9; Xcode 2.4
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Did you connect all your buttons to your script? and did you name them all properly?

Hi Dave,

there is no name property of a button.
Maybe you can use the title property instead

Greetings, Dave… and welcome to macscripter.

StefanK, what do you mean there’s no name property? Of course there is, and that could be the root of the problem. In my opinion, every applescript object should have a name, and testing against the title could lead to added work later, especially in the case of controls whose title may change. Make sure that in the applescript pane for each of the buttons, that you have a Name set in the field at the top. This is different from the identifier or title fields available in other panes. Also in the applescript pane, make sure that the checkbox for your script is checked. Probably is, but if not that could be the problem.

If I’m not mistaken, you can’t compare a string using the = operator. I think that if you coerce it to unicode then you can use the equal sign, but I usually use “is”. Try…

if name of theObject is "Power" then

…or use a more wholesome version…

if name of theObject is equal to "Power" then

If that doesn’t work, try adding…

log "clicked handler"

…inside of your clicked handler but outside any if blocks, which will log the message to the run log or the console whenever any properly connected button sends it’s clicked message. That way you can see if any of them are actually sending the message. As an aside, you probably don’t need to use the “action” handler.

Good luck,
j

Hi jobu,

sorry, you’re right, I’ve just taken a look at the dictionary and there isn’t a property name of class button.
But the dictionaries often don’t tell the truth :wink:

OK, very interesting.

Using “=” works in my non-Studio Applescript version, but I went ahead and changed it.

hendo13’s question of “Did you connect all your buttons to your script?” is the thing, so it’s all nothing but classic newbie mistakes.

Not only does the script name need to be shown in the Inspector window, you have to go ahead and select it and click on it and make sure the little blue dot has a black dot inside. This also puts a hyphen in the Nib event handler item, which I had seen in screen captures, but which I did not know how to make happen.

So now everthing works.

Thanks.

-Dave

Notice the inheritance; name is inherited from the item class (of the Application Suite).

Thanks Bruce,

AS still confuses me sometimes :wink: