Greetings,
The first problem I see, is that you do not reference a combo box in the manner in which you’ve posted. In fact, a combobox IS a type of text field, so referencing it like you’ve done is redundant and incorrect. To reference the combo box, use something like…
tell combo box "myComboBox" of window "myWindow"...
To get an item to receive drag and drop’s you typically need to do two things. First, attach a launch-time handler like ‘awake from nib’ to the object and register your drag types. I use the ‘awake from nib’ handler of the combobox…
on awake from nib theObject
tell theObject to register drag types {"file names"}
end awake from nib
This will let the application know when it starts up that when something is dropped on it, it should try to extract the paths of all the objects. Next, attach a ‘drop’ handler to the object and provide some code for doing something. The following code adds a new combo box item containing the path of the dropped file(s) to the combo box’s list…
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
repeat with thePath in thePaths
make new combo box item at end of combo box items of combo box "myComboBox" of window "myWindow" with data (thePath as string)
end repeat
end if
end drop
What seems to be your major problem here, is that for some reason (a bug?!) you cannot drop on any part of the combo box except the highlighted border when the combo box is first responder. You can drop normally on it when it’s not the focused object, but otherwise only the border is a valid drop target… as you’ve found.
I looked a bit and couldn’t find a documented way around this problem, so here’s a workaround I found to get the job done. Set up an extra object, like a horizontal line (technically a box). You could use another type of object, but it must be one that can be made first responder. You could also use an object that is already part of your interface, assuming that it does not cause undesired effects (like the object becoming highlighted when IT receives focus). That is why I find boxes to be particularly useful, as they do not have a highlighted border when focused. Place that object in a corner or off to the side of your window. I used a line object named “sponge”. Then, connect the ‘drag entered’ handler of your combo box to your script and enter this code…
on drag entered theObject drag info dragInfo
tell window "myWindow"
set first responder to box "sponge"
end tell
end drag entered
What this will do is force the combo box to drop it’s focus every time something is dragged onto it and allow it’s entire text field to be a drop zone. As I said, the object you change focus to will become the first responder so make sure you select that object wisely to avoid unusual or unattractive results.
I can’t guarantee this will work under all circumstances, but it worked in my test project. Once your project is working good, or you have your drop working as desired, just move the sponge off of the screen or hide it behind another object and you should have a good workaround for this quirk.
Good luck,
j