Drag file from finder onto text entry field, get path


(Max Wyss) #1

I may be too stupid or just not have found it.

What I want to accomplish is relatively simple.

I have an applescript-objective-c application created in Xcode. In the main window, I have a text field which does contain the path to a file (which will later on be processed). I also have a button which opens an Open File dialog to get that path.

What I now would like to make is the ability for the user to drag a file onto that field, and have its path displayed (as POSIX path).

Any help to accomplish this, or to the right place to find out more is highly appreciated.

Thanks in advance.

Max.


(Shane Stanley) #2

The easiest solution is to use a text view rather than a text field.


(Max Wyss) #3

Thanks for the response. Please forgive me, but I am too much of a beginner in this field, so that it is a bit too terse.

I did look around, and most references for drag and drop point to UIkit, which is becoming available soon.

Examples/tutorials for Mac apps cover pictures, but not text.


(Shane Stanley) #4

If you drag in an NSTextView instead of an NSTextField, you get the drag-and-drop of files with it for free. Another alternative is to use anNSPathControl.

That doesn’t mean you can’t do it with a text field – but it is reasonably complicated.