Well, yes… everything is possible.
There are a lot of factors involved here. First, when using a text field there are only a few methods, even at the cocoa level, that govern how the text field displays text. Alignment is the only one which seems to apply to your situation. But, as you’ve said, there are limitations to the abilities of the text field, notably the ability (or lack thereof) to make the text break on the left rather than the right. Without going back on my original statement that ‘everything is possible’, this is going to be a VERY large obstacle for you under these circumstances. The text field class is actually a subclass of nscontrol, rather than nstext. It offers no actual text handling methods, so you would have to programmatically manipulate everything to get the display characteristics you want. You would have to use custom cocoa methods extensively to grab the text, measure it by it’s font/glyph-level characteristics, manually crop the string to an exact width/length, and reinsert the text into the field… all the while manually toggling the left/right alignment in case the contents do not exceed the width of the field. There are many more obstacles I found testing this out, and have yet to find a way to do this. I’m certainly no guru with obj-c, but I wouldn’t have a clue how to go about implementing this without looking up and learning all about fonts and text foundation… yawn! Resizing the text field, losing focus, inserting new text, all are obstacles that cause their own new problems.
The text view class offers some more options. There is the base writing direction, control over the insertion point, and better string evaluation abilities. Still, there isn’t any great support for this, so you’d end up writing a lot of custom code to evaluate the string, draw custom text container, blah, blah…
As far as table cells go, if you were to find a method that worked well for a text field, you could probably pretty easily transfer it over to a table text cell. Again, though, that’s a heavy programatic task.
I guess my first advice would be to find another way. Perhaps add another text field or table column to your project that could display the file name, and then use the existing one to show the full path… or vice versa. You could use a contextual menu, or popup button… you could use a panel or drawer… or find some other creative method of displaying the information you wish to convey in an easier-to-access manner. You could also manually read the string and it’s length, edit it to a length known to fit inside the field, and then chop it and re-insert it. A resizable text field would add more complications to this method.
Sorry I don’t have a good solution for you. The text foundation is an english, left-right based text structure, so finding another way is going to require some serious knowledge of cocoa to get a solid solution to this problem. I’m pretty sure that applescript doesn’t have the exact answers you’re looking for.
Good luck,
j