How to connect a button's Sent Action in Xcode for a custom Automator Action project
Asked Answered
C

3

6

I'm in the Interface Builder of Xcode, creating an Cocoa-Applescript custom Automator Action. I have a Button and a ComboBox menu in the interface. I'd like to fill the content values of the ComboBox's menu when the user clicks the Button. I've created the

on buttonSentAction_(sender)
    -- set popupMenuContentValues of my parameters() to aList as list
    my popupMenu's addItemsWithObjectValues_(aList)
end buttonSentAction_

handler in the applescript file, but when I ctrl drag from the button to the File's Owner, the File's Owner does not highlight for me to drop the connection. What I'm expecting is for it to drop and give me the option of choosing the buttonSentAction_ handler to receive the sent action. If I right-click on File's Owner, the received action handler I've created in the Applescript controller file does not show up. (Note, I'm still unsure about the correct line to populate the ComboBox Menu inside that handler, too.) Screen Grab of linking combobox to File's Owner

I can see in the "FM to Named Text Boxes" sample Automator Action project at macosxautomation.com has a button in the IB where you can see in the Bindings Inspector that the button's sent action is in fact connected to the File's Owner, and that the applescript file has that matching handler. Also, I the controller for File's Owner is by default set to the applescript file. I'm missing something specific about hooking up sent actions in an Automator Action Project, obviously. Any help?

Coastwise answered 20/5, 2014 at 4:51 Comment(1)
There are a couple similar questions on stackoverflow, where folks can't connect to the File's Owner, but they were not Automator Action projects.Coastwise
C
1

Update: I got it to work. The key was that you have to create an Outlet for the object before you can then bind to a Sent Action Handler.

I deleted the button and started over, with a new naming scheme. This time, the File's Owner received the drag, and everything connected to the sent action and it works as expected. I did things exactly as I had before, so it is a mystery why the first action handler could not receive the Sent Action in IB.

Sample Code below:

on searchTypeMatrixWasClicked_(sender)
    -- called with the matrix sent action
    set theIndex to (actionTypeIndex of my parameters()) as integer
    if theIndex is 0 then
    -- do stuff, etc.
    else if theIndex is 1 …
    end if
end

Bindings Inspector in IB

Coastwise answered 26/5, 2014 at 15:56 Comment(1)
Sure, just added the relevant Event Handler code, and a screen shot of the Bindings Inspector.Coastwise
D
0

Maybe this will help you.

I know that it does not work by control + dragging to File's Owner for some reason, but you can connect to the File's Owner by going to the bindings inspector.

This is not exactly what you are doing, because you want to send information to a handler, but I think the trick is to use the Parameters Object. You have to create a key to hold the value, and access it with AppleScript using get |keyname| of my parameters() as integer, (or string,list) for example. see The Structure of the on run Command Handler.

Below I provide an example of how I connected a property to a popup button.

See pictures: enter image description here enter image description here

Disavow answered 26/5, 2014 at 12:49 Comment(3)
You are describing how to set up a Binding, which I have no problem with. My question is asking how to connect File's Owner to a Sent Action, which is not the same as a Binding to a value like you demonstrate.Coastwise
@Coastwise I see what you are saying. I am interested in finding this out too. I will experiment a bit.Disavow
I just went through all the steps again, and this time it worked. Big mystery.Coastwise
E
-1

I haven't worked with Automator projects to connect actions to custom objects in Interface Builder you either:

  • Set your existing object as the owner in instantiateWithOwner:topLevelObjects:. Then set the class accordingly in the Nib file.

  • Instantiate a new custom object by dragging a NSObject to your Nib, it will show up below the "Parameters" object in your screenshot. Then set it's class to any object that you want IB to instantiate. You should also retain this object with an Outlet.

Extravasation answered 26/5, 2014 at 2:13 Comment(1)
Thanks for the efforts, but I don't think this answer makes sense for an Applescript Automator action project. File's Owner should point to the instance of the owner file.Coastwise

© 2022 - 2024 — McMap. All rights reserved.