I was given a cocoa class written by Craig Williams that inherits from NSTextField and handles Drag and Drop. I use it for a set of text fields. My problem is that I don’t know how to get a cocoa object to notify the main script that something has been done - in this case, the text field string has been changed.
This is necessary in order to verify that the string is a path of a certain type of file, or a folder, and then change certain other script variables accordingly. The working method is in the implementation section:
Applescript Studio handled drag and drop a bit awkwardly but at least it was in the same script and other script variables could be affected by the drop. A solution to my notification problem would go a long way helping me to learn ObjectiveC
Well, I’m not exactly sure of the answer. And thought I’d wait to see if someone else has a solution. But I have some ideas that I think might pan out for you. It’s also hard because you didn’t post much detail on how the rest of your app is structured… But here’s a couple things I’d try, assuming you’re trying to pass a notification from the Obj-C class you got to your AppDelegate.applescript:
in your AppDelegate, create a handler that’s
you’ll want to make sure the variables you need changed are global.
Then, in interface builder:
go to the library and search in classes for the Obj-C class you got, and drag that (should be a blue cube) onto your MainMenu.xib. Hold control and drag from that class to your AppDelegate’s blue cube. A list of receivers should pop-up, and select “yourNewHandler”.
Now what I don’t know, partly because I don’t know how you set up your app, and partly because I don’t know Obj-C (so I’m not exactly sure how that class works), is how to get the text that was dragged into yourNewHandler. If your text is dragged into a textfield,
then your newHandler would be something like
I’ve got a text field that’s populated with a file path from a pop up button and a file that the usernavigates to.
Trouble is, just plonking the text into the field doesn’t generate a call to a method, so the routine ‘on yourNewHandler_(sender)’ mentioned above won’t get called, unless the field is actually edited.
We need some way of updating the preference bindings. Is there such a way?
I have a clumsy solution to my problem. It’s too involved. There must be something simpler.
I have an ASOC AppDelegate containing ids for 2 text fields of class “TextFieldDrop”. The awakeFromNib method passes the id of the main script to the text fields. The continueDrop method is the one contacted when the text field has accepted a drop. continueDrop is called before the text is changed in the text field. I’m not convinced this is the best way to do it.
property parent : class "NSObject"
property gedFileTextField : missing value
property outFolderTextField : missing value
property gedFileText : missing value
property outFolderText : missing value
property gedFound : true
-- Insert code here to initialize your application before any files are opened
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
theField's setStringValue_("text string changed")
my gedFileTextField's setMainScript_(me)
my outFolderTextField's setMainScript_(me)
I added a variable and a method to Craig Williams’ TextField class: