NSMenuItem fails on submenu

I’m trying to get the submenu of a menu in AppleScriptObj-C
It fails because Script Debugger keeps capitalizing the “m” in submenu when it compiles these lines

set m to menuBar's itemWithTitle:"File"
set sm to m's submenu

After I compile, the line becomes…

set sm to m’s subMenu

the “m” should be lower case or the call fails, yet I cant seem to get it to stay lowercase.

  1. Where does menuBar come from?
  2. Do you use framework "AppKit" (you have to)?
  3. Actually the syntax is supposed to be submenu()
1 Like

Actually, you don’t need the (), but either way it keeps capitalizing the M and yes I have all the requisite frameworks loaded, that’s not the issue.

I think i found a workaround. In another handler i have a variable called subMenu. I think that’s what’s confusing Script Debugger, because even tho it’s a local variable in the other handler, script debugger forces it in other handlers. I changed the name in the other handler to sub_menu and it stopped capitalizing and now it works.
Odd

That’s normal AppleScript behavior – nothing to do with Script Debugger. A script can only have one form of capitalisation. (It used to be that AppleScript turned all identifiers to all-lowercase internally, making different cases impossible.)

1 Like

As Shane already explained, that’s standard AppleScript behavior.

If you ever notice that your variable’s capitalization changes then it’s a safe bet you already used the same variable name with a different capitalization someplace else in the script.