Wednesday, August 16, 2017

#1 2017-07-02 05:52:21 am

robdut
Member
Registered: 2009-09-02
Posts: 297

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:

Applescript:

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:

Applescript:

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

Last edited by robdut (2017-07-02 06:27:59 am)

Offline

 

#2 2017-07-02 06:25:15 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5079

Re: Can not connect button to action in Xcode

What version of OS and Xcode?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-07-06 06:49:34 am

robdut
Member
Registered: 2009-09-02
Posts: 297

Re: Can not connect button to action in 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

Last edited by robdut (2017-07-06 07:04:50 am)

Offline

 

#4 2017-07-06 07:08:15 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5079

Re: Can not connect button to action in Xcode

robdut wrote:

OS 10.12.5 and Xcode 8.3.1


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

Applescript:

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...)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2017-07-06 09:32:13 am

robdut
Member
Registered: 2009-09-02
Posts: 297

Re: Can not connect button to action in Xcode

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

Offline

 

#6 2017-07-06 05:52:20 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5079

Re: Can not connect button to action in Xcode

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2017-07-18 05:03:45 am

robdut
Member
Registered: 2009-09-02
Posts: 297

Re: Can not connect button to action in Xcode

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:

Applescript:

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?

Applescript:

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

which runs fine.

Offline

 

#8 2017-07-18 06:25:21 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5079

Re: Can not connect button to action in Xcode

robdut wrote:

I imagine the apostrophes are throwing it off?



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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)