Can not connect button to action in Xcode

Hi All,

A strange problem has cropped up. For some time I have noticed that if I add a new IBAction in my script:

on displayMessage_(sender)
	display dialog "Message"
end displayMessage_

it doesn’t show in the list of actions when trying to connect to a button or menu item. Sometimes I could get it to work by quitting Xcode or fiddling around but now it won’t happen. Oddly I could connect it to another existing action but then if I disconnect it that action then no longer appears in the list!

App compiles fine, I can add and connect new outlets to objects, new script code runs fine.

Thinking my scripts were too large perhaps, I made a new tiny test app:

script AppDelegate
	property parent : class "NSObject"
	
	property theWindow : missing value
	
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_

       on displayMessage_(sender)
	   display dialog "Message"
       end displayMessage_

end script

and same deal. Can not connect button to displayMessage_(sender)

I seem to be plagued by odd Xcode/applescript behavior but fixed some previous issues by reinstalling new OS and Xcode. But this seems to be a constant.

Any ideas?

Thx, Rob

What version of OS and Xcode?

Shane,

It’s OS 10.12.5 and Xcode 8.3.1

I tried the small test app on my iMac and did get it to recognize the IBOutlet there. But Still can’t add one to the existing app’s script and connect to it. I have Xcode 7x on the iMac so will try that today but I think it was showing the same behavior before. I think my project may just be too old (they get weird after years of OS and Xcode changes) and the scripts too big. I cloned the iMac system to the laptop a while ago and fixed some Xcode bugginess here but also have reinstalled Xcode several times with no change in the IBOutlet situation. Also several clean installs of OS.

Rob

In that case you shouldn’t be using the old underscore terminology. Use:

on displayMessage:sender
	display dialog "Message"
end displayMessage:

It’s been around since 10.9, and it wouldn’t surprise me if Xcode started ignoring the old approach.

(This also suggests you’re editing in Xcode rather than an external script editor, which is making things harder for yourself…)

Yes I tried underscore and the new interleaved method. Neither work though. True I should try an external editor… just haven’t shelled out the $99 yet for script debugger. Not sure the external editor would change the IB Outlet situation though as Xcode has to build the project and kale the connections.

Thanks, rob

You can use Script Editor as an external editor, too, although it has issues. You may find that simply “cleaning” your code by compiling it in an external editor helps. Make sure it’s saved with linefeeds rather than carriage returns, though – that can throw Xcode otherwise.

Yes the external editor did the trick! Both script editor and Script Debugger (trying the free trial.) I never felt the need for an external editor before, maybe because most of my apps are in OBJc except for this one in question and Xcode has always pointed me to the problem lines of AppleScript. But now I can see that they have become corrupted somehow and are not in sync with Xcode and IB. Thanks Shane.

I did find that some compound lines were undone by the the AppleScript editors:

set theSourceItems to Backset's arrangedObjects()'s objectAtIndex_(i - 1)'s valueForKey_("sourcefiles")

became 

set theSourceItems to (Backset's arrangedObjects()'s objectAtIndex:(i - 1)'s valueForKey:"sourcefiles")

Easy enough to break those down into two lines. I imagine the apostrophes are throwing it off?

set theSourceItemsObject to Backset's arrangedObjects()'s objectAtIndex:(i - 1)
set theSourceItems to (theSourceItemsObject's valueForKey:"sourcefiles")

which runs fine.

Yes – you need to break it, or add another pair of parentheses.